From 840438559261fd64b07d1bce489d352e6d553da5 Mon Sep 17 00:00:00 2001 From: Jahn Thomas Fidje Date: Fri, 23 Sep 2022 03:06:37 +0200 Subject: Add feature to enqueue dependents at the front of queues (#1696) * Add feature to enqueue dependents at the front of queues * Add documentation for the Dependency(enqueue_at_front=...) parameter * docs: Add `enqueue_at_front` to list of parameters for Dependency * test: Update dependency test to not rely on Redis ordering * refactor: Save enqueue_at_front boolean in job.meta instead of separate instance attr * fix: Made enqueue_at_front an instance attribute instead of putting it inside meta --- docs/docs/index.md | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'docs') diff --git a/docs/docs/index.md b/docs/docs/index.md index 0748846..fb2a68b 100644 --- a/docs/docs/index.md +++ b/docs/docs/index.md @@ -167,6 +167,7 @@ The `Dependency(jobs=...)` parameter accepts: - a string representing a single job id - a Job object - an iteratable of job id strings and/or Job objects +- `enqueue_at_front` boolean parameter to put dependents at the front when they are enqueued Example: @@ -177,9 +178,17 @@ from rq import Queue queue = Queue(connection=Redis()) job_1 = queue.enqueue(div_by_zero) -dependency = Dependency(jobs=[job_1], allow_failure=True) # allow_failure defaults to False +dependency = Dependency( + jobs=[job_1], + allow_failure=True, # allow_failure defaults to False + enqueue_at_front=True # enqueue_at_front defaults to False +) job_2 = queue.enqueue(say_hello, depends_on=dependency) -# job_2 will execute even though its dependency (job_1) fails + +""" + job_2 will execute even though its dependency (job_1) fails, + and it will be enqueued at the front of the queue. +""" ``` @@ -269,10 +278,10 @@ There are two options: #### Arguments: -| | plain text | json | [literal-eval](https://docs.python.org/3/library/ast.html#ast.literal_eval) | -|-|-|-|-| -| keyword | `[key]=[value]` | `[key]:=[value]` | `[key]%=[value]` | -| no keyword | `[value]` | `:[value]` | `%[value]` | +| | plain text | json | [literal-eval](https://docs.python.org/3/library/ast.html#ast.literal_eval) | +| ---------- | --------------- | ---------------- | --------------------------------------------------------------------------- | +| keyword | `[key]=[value]` | `[key]:=[value]` | `[key]%=[value]` | +| no keyword | `[value]` | `:[value]` | `%[value]` | Where `[key]` is the keyword and `[value]` is the value which is parsed with the corresponding parsing method. -- cgit v1.2.1