Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup action task params objects after successful execution #55227

Merged
merged 15 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ const taskRunnerFactoryInitializerParams = {
spaceIdToNamespace,
encryptedSavedObjectsPlugin: mockedEncryptedSavedObjectsPlugin,
getBasePath: jest.fn().mockReturnValue(undefined),
getScopedSavedObjectsClient: jest.fn().mockReturnValue(savedObjectsClientMock.create()),
};

beforeEach(() => {
jest.resetAllMocks();
actionExecutorInitializerParams.getServices.mockReturnValue(services);
taskRunnerFactoryInitializerParams.getScopedSavedObjectsClient.mockReturnValue(
savedObjectsClientMock.create()
);
});

test(`throws an error if factory isn't initialized`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { ActionExecutorContract } from './action_executor';
import { ExecutorError } from './executor_error';
import { ActionsCoreStart } from '../shim';
import { RunContext } from '../../../../../plugins/task_manager/server';
import { PluginStartContract as EncryptedSavedObjectsStartContract } from '../../../../../plugins/encrypted_saved_objects/server';
import { ActionTaskParams, GetBasePathFunction, SpaceIdToNamespaceFunction } from '../types';
Expand All @@ -14,6 +15,7 @@ export interface TaskRunnerContext {
encryptedSavedObjectsPlugin: EncryptedSavedObjectsStartContract;
spaceIdToNamespace: SpaceIdToNamespaceFunction;
getBasePath: GetBasePathFunction;
getScopedSavedObjectsClient: ActionsCoreStart['savedObjects']['getScopedSavedObjectsClient'];
}

export class TaskRunnerFactory {
Expand Down Expand Up @@ -43,6 +45,7 @@ export class TaskRunnerFactory {
encryptedSavedObjectsPlugin,
spaceIdToNamespace,
getBasePath,
getScopedSavedObjectsClient,
} = this.taskRunnerContext!;

return {
Expand Down Expand Up @@ -93,6 +96,10 @@ export class TaskRunnerFactory {
executorResult.data,
executorResult.retry == null ? false : executorResult.retry
);
} else if (executorResult.status === 'ok') {
mikecote marked this conversation as resolved.
Show resolved Hide resolved
mikecote marked this conversation as resolved.
Show resolved Hide resolved
// Cleanup action_task_params object now that we're done with it
const savedObjectsClient = getScopedSavedObjectsClient(fakeRequest);
await savedObjectsClient.delete('action_task_params', actionTaskParamsId);
mikecote marked this conversation as resolved.
Show resolved Hide resolved
}
},
};
Expand Down
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/actions/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export class Plugin {
encryptedSavedObjectsPlugin: plugins.encryptedSavedObjects,
getBasePath,
spaceIdToNamespace,
getScopedSavedObjectsClient: core.savedObjects.getScopedSavedObjectsClient,
});

const executeFn = createExecuteFunction({
Expand Down