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

Skip updating task document if task is cancelled #111740

Closed
wants to merge 3 commits into from
Closed
Changes from all 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
36 changes: 22 additions & 14 deletions x-pack/plugins/task_manager/server/task_running/task_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ export class TaskManagerRunner implements TaskRunner {
withSpan({ name: 'run', type: 'task manager' }, () => this.task!.run())
);
const validatedResult = this.validateResult(result);

const processedResult = await withSpan({ name: 'process result', type: 'task manager' }, () =>
this.processResult(validatedResult, stopTaskTimer())
);
Expand Down Expand Up @@ -407,7 +408,6 @@ export class TaskManagerRunner implements TaskRunner {
this.task = undefined;
return task.cancel();
}

this.logger.debug(`The task ${this} is not cancellable.`);
}

Expand Down Expand Up @@ -499,20 +499,28 @@ export class TaskManagerRunner implements TaskRunner {
unwrap
)(result);

this.instance = asRan(
await this.bufferedTaskStore.update(
defaults(
{
...fieldUpdates,
// reset fields that track the lifecycle of the concluded `task run`
startedAt: null,
retryAt: null,
ownerId: null,
},
this.instance.task
// If the task has exceeded the configured timeout by the time it returns
// we ignore the result
if (!this.isExpired) {
this.instance = asRan(
await this.bufferedTaskStore.update(
defaults(
{
...fieldUpdates,
// reset fields that track the lifecycle of the concluded `task run`
startedAt: null,
retryAt: null,
ownerId: null,
},
this.instance.task
)
)
)
);
);
} else {
this.logger.warn(
`Recurring task completed but doc will not be updated because task was cancelled`
);
}

return fieldUpdates.status === TaskStatus.Failed
? TaskRunResult.Failed
Expand Down