-
Notifications
You must be signed in to change notification settings - Fork 11.7k
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
feat(core): Cancel runner task on timeout in external mode #12101
Merged
ivov
merged 20 commits into
master
from
cat-405-task-that-times-out-is-left-running-on-task-runner
Dec 10, 2024
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c7c587d
WIP
ivov eedf67c
Send msg instead
ivov 8fb7abc
Adjust phrasing
ivov 7f0f8fb
Fix typecheck
ivov 2d185fc
Remove commented out code
ivov 896549d
Add TODO
ivov 06261de
Fix test
ivov 8c885d3
Adjust msg based on mode
ivov 00d7fb8
Improve readability
ivov b98f1cc
Add timeout runner-side
ivov 828d59f
Fix typecheck
ivov 4efd5f6
Better syntax
ivov ce94ef5
Pass `timeout` to `runInNewContext`
ivov f4a2449
Move `clearTimeout` to `finally` block
ivov 4c1f5ff
Handle cancellation at request level
ivov 731068e
Add `N8N_RUNNERS_TASK_TIMEOUT` to config file
ivov 8b75bdf
Remove event listener
ivov 1d2ee31
Add task broker cancellation test
ivov 69de17d
Add test for `TaskRunner.taskCancelled`
ivov ffaba80
Use `TaskCancelledError` with `reason`
ivov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/@n8n/task-runner/src/js-task-runner/errors/task-cancelled-error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { ApplicationError } from 'n8n-workflow'; | ||
|
||
export class TaskCancelledError extends ApplicationError { | ||
constructor(reason: string) { | ||
super(`Task cancelled: ${reason}`, { level: 'warning' }); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
packages/@n8n/task-runner/src/js-task-runner/errors/timeout-error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ApplicationError } from 'n8n-workflow'; | ||
|
||
export class TimeoutError extends ApplicationError { | ||
description: string; | ||
|
||
constructor(taskTimeout: number) { | ||
super( | ||
`Task execution timed out after ${taskTimeout} ${taskTimeout === 1 ? 'second' : 'seconds'}`, | ||
); | ||
|
||
const subtitle = 'The task runner was taking too long on this task, so the task was aborted.'; | ||
|
||
const fixes = { | ||
optimizeScript: | ||
'Optimize your script to prevent long-running tasks, e.g. by processing data in smaller batches.', | ||
ensureTermination: | ||
'Ensure that all paths in your script are able to terminate, i.e. no infinite loops.', | ||
}; | ||
|
||
const suggestions = [fixes.optimizeScript, fixes.ensureTermination]; | ||
|
||
const suggestionsText = suggestions | ||
.map((suggestion, index) => `${index + 1}. ${suggestion}`) | ||
.join('<br/>'); | ||
|
||
const description = `${subtitle} You can try the following:<br/><br/>${suggestionsText}`; | ||
|
||
this.description = description; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌