mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
# Backport This will backport the following commits from `main` to `8.x`: - [Update task state version after execution. (#215559)](https://github.com/elastic/kibana/pull/215559) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Ersin Erdal","email":"92688503+ersin-erdal@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-03-27T23:58:41Z","message":"Update task state version after execution. (#215559)\n\nThis PR fixes the missing stateVersion update in the `partialUpdate`\nmethod.\n\n\n[update](https://github.com/elastic/kibana/blob/main/x-pack/platform/plugins/shared/task_manager/server/buffered_task_store.ts#L62)\nmethod already uses the validated task that already has the stateVersion\nfield.\n\nbut the `partialUpdate` misses it.","sha":"6373b0c65a084088f4ac455c59bdc11e72b1b5d7","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:ResponseOps","v9.0.0","backport:version","v9.1.0","v8.19.0"],"title":"Update task state version after execution.","number":215559,"url":"https://github.com/elastic/kibana/pull/215559","mergeCommit":{"message":"Update task state version after execution. (#215559)\n\nThis PR fixes the missing stateVersion update in the `partialUpdate`\nmethod.\n\n\n[update](https://github.com/elastic/kibana/blob/main/x-pack/platform/plugins/shared/task_manager/server/buffered_task_store.ts#L62)\nmethod already uses the validated task that already has the stateVersion\nfield.\n\nbut the `partialUpdate` misses it.","sha":"6373b0c65a084088f4ac455c59bdc11e72b1b5d7"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/215559","number":215559,"mergeCommit":{"message":"Update task state version after execution. (#215559)\n\nThis PR fixes the missing stateVersion update in the `partialUpdate`\nmethod.\n\n\n[update](https://github.com/elastic/kibana/blob/main/x-pack/platform/plugins/shared/task_manager/server/buffered_task_store.ts#L62)\nmethod already uses the validated task that already has the stateVersion\nfield.\n\nbut the `partialUpdate` misses it.","sha":"6373b0c65a084088f4ac455c59bdc11e72b1b5d7"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Ersin Erdal <92688503+ersin-erdal@users.noreply.github.com>
This commit is contained in:
parent
7c957f0fc3
commit
f5f8a860fa
3 changed files with 30 additions and 4 deletions
|
@ -375,5 +375,26 @@ describe('Buffered Task Store', () => {
|
|||
expect(await results[2]).toMatchObject(partialTasks[2]);
|
||||
expect(await results[3]).toMatchObject(partialTasks[3]);
|
||||
});
|
||||
|
||||
test(`updates the stateVersion`, async () => {
|
||||
const taskStore = taskStoreMock.create({ stateVersion: 2 });
|
||||
const bufferedStore = new BufferedTaskStore(taskStore, {});
|
||||
|
||||
const task = taskManagerMock.createTask();
|
||||
const partialTask = {
|
||||
id: task.id,
|
||||
version: task.version,
|
||||
status: 'running' as TaskStatus,
|
||||
};
|
||||
|
||||
taskStore.bulkPartialUpdate.mockResolvedValue([asOk(partialTask)]);
|
||||
|
||||
expect(
|
||||
await bufferedStore.partialUpdate(partialTask, { validate: false, doc: task })
|
||||
).toMatchObject(partialTask);
|
||||
expect(taskStore.bulkPartialUpdate).toHaveBeenCalledWith([
|
||||
{ ...partialTask, stateVersion: 2 },
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -74,12 +74,14 @@ export class BufferedTaskStore implements Updatable {
|
|||
options: { validate: boolean; doc: ConcreteTaskInstance }
|
||||
): Promise<ConcreteTaskInstance> {
|
||||
// merge the partial updates with the doc and validate
|
||||
this.taskStore.taskValidator.getValidatedTaskInstanceForUpdating(
|
||||
const { stateVersion } = this.taskStore.taskValidator.getValidatedTaskInstanceForUpdating(
|
||||
{ ...options.doc, ...partialDoc },
|
||||
{ validate: options.validate }
|
||||
);
|
||||
|
||||
const result = await unwrapPromise(this.bufferedPartialUpdate(partialDoc));
|
||||
const result = await unwrapPromise(
|
||||
this.bufferedPartialUpdate({ ...partialDoc, ...(stateVersion ? { stateVersion } : {}) })
|
||||
);
|
||||
|
||||
// merge the partial update result with the doc and validate
|
||||
return this.taskStore.taskValidator.getValidatedTaskInstanceFromReading(
|
||||
|
|
|
@ -11,13 +11,16 @@ import type { TaskStore } from './task_store';
|
|||
interface TaskStoreOptions {
|
||||
index?: string;
|
||||
taskManagerId?: string;
|
||||
stateVersion?: number;
|
||||
}
|
||||
export const taskStoreMock = {
|
||||
create({ index = '', taskManagerId = '' }: TaskStoreOptions = {}) {
|
||||
create({ index = '', taskManagerId = '', stateVersion }: TaskStoreOptions = {}) {
|
||||
const mocked = {
|
||||
taskValidator: {
|
||||
getValidatedTaskInstanceFromReading: jest.fn().mockImplementation((task) => task),
|
||||
getValidatedTaskInstanceForUpdating: jest.fn().mockImplementation((task) => task),
|
||||
getValidatedTaskInstanceForUpdating: jest
|
||||
.fn()
|
||||
.mockImplementation((task) => ({ ...task, ...(stateVersion ? { stateVersion } : {}) })),
|
||||
},
|
||||
convertToSavedObjectIds: jest.fn(),
|
||||
update: jest.fn(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue