diff options
author | Selwin Ong <selwin.ong@gmail.com> | 2019-03-16 08:22:12 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-16 08:22:12 +0700 |
commit | b0727e63fd95be415a823c191d87d4c30b4510d8 (patch) | |
tree | 42023f7b98a99a13b88aa31800be7a7fe14a7cad | |
parent | f963d46a572a1deee4117c0f666766b3ce89fbcd (diff) | |
download | rq-b0727e63fd95be415a823c191d87d4c30b4510d8.tar.gz |
queue.enqueue() no longer accepts `timeout` argument (#1055)
-rw-r--r-- | CHANGES.md | 2 | ||||
-rw-r--r-- | docs/docs/index.md | 7 | ||||
-rw-r--r-- | docs/docs/results.md | 8 | ||||
-rw-r--r-- | rq/queue.py | 11 | ||||
-rw-r--r-- | tests/test_queue.py | 11 |
5 files changed, 17 insertions, 22 deletions
@@ -16,6 +16,8 @@ Backward incompatible changes: - `Worker` names are now randomized. Thanks @selwin! +- `timeout` argument on `queue.enqueue()` has been deprecated in favor of `job_timeout`. Thanks @selwin! + - Sentry integration has been reworked: * RQ now uses the new [sentry-sdk](https://pypi.org/project/sentry-sdk/) in place of the deprecated [Raven](https://pypi.org/project/raven/) library * RQ will look for the more explicit `RQ_SENTRY_DSN` environment variable instead of `SENTRY_DSN` before instantiating Sentry integration diff --git a/docs/docs/index.md b/docs/docs/index.md index 28b900a..d8c166a 100644 --- a/docs/docs/index.md +++ b/docs/docs/index.md @@ -61,7 +61,7 @@ In addition, you can add a few options to modify the behaviour of the queued job. By default, these are popped out of the kwargs that will be passed to the job function. -* `timeout` specifies the maximum runtime of the job before it's interrupted +* `job_timeout` specifies the maximum runtime of the job before it's interrupted and marked as `failed`. Its default unit is second and it can be an integer or a string representing an integer(e.g. `2`, `'2'`). Furthermore, it can be a string with specify unit including hour, minute, second(e.g. `'1h'`, `'3m'`, `'5s'`). * `result_ttl` specifies the expiry time of the key where the job result will be stored @@ -72,8 +72,9 @@ job function. * `job_id` allows you to manually specify this job's `job_id` * `at_front` will place the job at the *front* of the queue, instead of the back +* `description` to add additional description to enqueued jobs. * `kwargs` and `args` lets you bypass the auto-pop of these arguments, ie: - specify a `timeout` argument for the underlying job function. + specify a `description` argument for the underlying job function. In the last case, it may be advantageous to instead use the explicit version of `.enqueue()`, `.enqueue_call()`: @@ -82,7 +83,7 @@ In the last case, it may be advantageous to instead use the explicit version of q = Queue('low', connection=redis_conn) q.enqueue_call(func=count_words_at_url, args=('http://nvie.com',), - timeout=30) + job_timeout=30) ``` For cases where the web process doesn't have access to the source code running diff --git a/docs/docs/results.md b/docs/docs/results.md index 26087d6..5228104 100644 --- a/docs/docs/results.md +++ b/docs/docs/results.md @@ -68,7 +68,7 @@ This makes it possible to inspect and interpret the problem manually and possibly resubmit the job. -## Dealing with interruption +## Dealing With Interruptions When workers get killed in the polite way (Ctrl+C or `kill`), RQ tries hard not to lose any work. The current work is finished after which the worker will @@ -83,7 +83,7 @@ damage. Just sayin'. -## Dealing with job timeouts +## Dealing With Job Timeouts By default, jobs should execute within 180 seconds. After that, the worker kills the work horse and puts the job onto the `failed` queue, indicating the @@ -95,7 +95,7 @@ can be loosened (or tightened), by specifying it as a keyword argument to the ```python q = Queue() -q.enqueue(mytask, args=(foo,), kwargs={'bar': qux}, timeout=600) # 10 mins +q.enqueue(mytask, args=(foo,), kwargs={'bar': qux}, job_timeout=600) # 10 mins ``` You can also change the default timeout for jobs that are enqueued via specific @@ -108,7 +108,7 @@ high = Queue('high', default_timeout=8) # 8 secs low = Queue('low', default_timeout=600) # 10 mins # Individual jobs can still override these defaults -low.enqueue(really_really_slow, timeout=3600) # 1 hr +low.enqueue(really_really_slow, job_timeout=3600) # 1 hr ``` Individual jobs can still specify an alternative timeout, as workers will diff --git a/rq/queue.py b/rq/queue.py index 6aaabb9..52cf275 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -10,8 +10,8 @@ from redis import WatchError from .compat import as_text, string_types, total_ordering from .connections import resolve_connection from .defaults import DEFAULT_RESULT_TTL -from .exceptions import (DequeueTimeout, InvalidJobDependency, - InvalidJobOperationError, NoSuchJobError, UnpickleError) +from .exceptions import (DequeueTimeout, InvalidJobDependency, NoSuchJobError, + UnpickleError) from .job import Job, JobStatus from .utils import backend_class, import_attribute, utcnow, parse_timeout @@ -293,13 +293,8 @@ class Queue(object): 'by workers') # Detect explicit invocations, i.e. of the form: - # q.enqueue(foo, args=(1, 2), kwargs={'a': 1}, timeout=30) + # q.enqueue(foo, args=(1, 2), kwargs={'a': 1}, job_timeout=30) timeout = kwargs.pop('job_timeout', None) - if timeout is None: - timeout = kwargs.pop('timeout', None) - if timeout: - warnings.warn('The `timeout` keyword is deprecated. Use `job_timeout` instead', DeprecationWarning) - description = kwargs.pop('description', None) result_ttl = kwargs.pop('result_ttl', None) ttl = kwargs.pop('ttl', None) diff --git a/tests/test_queue.py b/tests/test_queue.py index 16a0e04..62a8f11 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -328,19 +328,16 @@ class TestQueue(RQTestCase): def test_job_timeout(self): """Timeout can be passed via job_timeout argument""" queue = Queue() - job = queue.enqueue(echo, 1, timeout=15) - self.assertEqual(job.timeout, 15) - job = queue.enqueue(echo, 1, job_timeout=15) self.assertEqual(job.timeout, 15) - + def test_default_timeout(self): """Timeout can be passed via job_timeout argument""" queue = Queue() job = queue.enqueue(echo, 1) self.assertEqual(job.timeout, queue.DEFAULT_TIMEOUT) - - job = Job.create(func=echo) + + job = Job.create(func=echo) job = queue.enqueue_job(job) self.assertEqual(job.timeout, queue.DEFAULT_TIMEOUT) @@ -348,7 +345,7 @@ class TestQueue(RQTestCase): job = queue.enqueue(echo, 1) self.assertEqual(job.timeout, 15) - job = Job.create(func=echo) + job = Job.create(func=echo) job = queue.enqueue_job(job) self.assertEqual(job.timeout, 15) |