nailgun
nailgun copied to clipboard
Make timeouts configurable on a per-call basis
Many calls require that you wait for a task to complete. For example, publishing a content view or syncing a repository takes a non-trivial amount of time, and a foreman task is created to track the progress of said tasks. Different types of calls require different timeouts. For example, publishing a content view might complete in just a few minutes, whereas syncing a repository may take several hours. It'd be nice to be able to control the timeout.
We can currently do this via the module-wide
nailgun.entity_mixins.TASK_TIMEOUT
variable. It's currently set to a default
of 300 (seconds). It's possible to fiddle with this setting, but using this
setting is extremely threading-unfriendly. What happens if two different threads
adust the timeout to different values, and then restore the timeout later on?
A better approach would be to let the timeout be specified on a per-call basis.
In the immediate future, we can add a timeout
kwarg to all of the helper
methods. Here are some examples of usage:
repository.sync(timeout=3600)
content_view.publish(timeout=300)
:+1:
:+1:
I am planning to work on this.
support some of the approaches:
context manager (the easiest to implement)
A general Context manager to configure nalgun global variables
from nailgun import Context
with Context(timeout=3600):
repository.sync()
A method in entities
rep = Repository.with_(timeout=3600).create(....)
A explicit arg on call
repository.sync(timeout=3600)
I like option 1 and 3.