mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 01:13:23 -04:00
Update task state version after execution. (#215559)
This PR fixes the missing stateVersion update in the `partialUpdate` method. [update](https://github.com/elastic/kibana/blob/main/x-pack/platform/plugins/shared/task_manager/server/buffered_task_store.ts#L62) method already uses the validated task that already has the stateVersion field. but the `partialUpdate` misses it.
This commit is contained in:
parent
ab07c23962
commit
6373b0c65a
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 },
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -73,12 +73,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 { 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