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

Add task timeout #52

Merged
merged 9 commits into from
Feb 12, 2025
Merged

Add task timeout #52

merged 9 commits into from
Feb 12, 2025

Conversation

AlanCoding
Copy link
Member

@AlanCoding AlanCoding commented Feb 7, 2025

Fixes #54

Obviously this needs an integration test, but I wanted to just get implementation structure now. It is functional, tested with the demo script.

EDIT: added tests

ERROR:dispatcher.worker.task:Worker 1 task canceled (uuid=1db13c11-a50a-4b0a-91c7-8cbc401c7436)
Traceback (most recent call last):
  File "/home/arominge/repos/dispatcher/dispatcher/worker/task.py", line 84, in run_callable
    return _call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/arominge/repos/dispatcher/tools/test_methods.py", line 28, in task_has_timeout
    time.sleep(5)
  File "/home/arominge/repos/dispatcher/dispatcher/worker/task.py", line 31, in task_cancel
    raise DispatcherCancel
dispatcher.worker.task.DispatcherCancel
DEBUG:dispatcher.pool:Worker 1 finished task (uuid=1db13c11-a50a-4b0a-91c7-8cbc401c7436), ct=16, expected cancel, canceled

There are some aesthetic changes we could make, like call it "timeout" instead of "cancel"... but obviously timeout uses the same mechanism as cancel. Maybe I'll just rename the exception to DispatcherInterrupt or something like that.

Also, I'm relatively happy with the structure, although it took some thought. I implemented "delayed" task in the "main" part of the code. It's non-obvious that timeouts will go in the pool part, but the pool can gate on capacity, and timeouts don't start until the worker actually starts running it. And this is definitely something we want enforced in the parent, in general.

@AlanCoding AlanCoding changed the title Add timeout param, only tested in demo so far Add timeout param Feb 10, 2025
@AlanCoding AlanCoding changed the title Add timeout param Add task timeout Feb 10, 2025
@AlanCoding AlanCoding marked this pull request as ready for review February 10, 2025 03:22
Copy link
Collaborator

@Alex-Izquierdo Alex-Izquierdo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a testcase where multiple tasks with different timeouts are enqueued? Since the timeout is managed in the main process I feel we should be able to prove that all the timeouts are honored concurrently in a correct manner.

dispatcher/pool.py Outdated Show resolved Hide resolved
dispatcher/pool.py Outdated Show resolved Hide resolved
dispatcher/pool.py Show resolved Hide resolved
dispatcher/pool.py Outdated Show resolved Hide resolved
dispatcher/pool.py Outdated Show resolved Hide resolved
@AlanCoding AlanCoding added awx needed for AWX MVP minimum set of issues to fix labels Feb 11, 2025
@AlanCoding
Copy link
Member Author

@Alex-Izquierdo from your last review I've changed the remaining SimpleNamespace classes for saving events. I'm otherwise done with this, unless you see something else.

@AlanCoding AlanCoding merged commit 0d7535a into ansible:main Feb 12, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awx needed for AWX MVP minimum set of issues to fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a task timeout
2 participants