mirror of https://github.com/peter4431/rq.git
Add support for dependent jobs in enqueue_many (#1897)
* Add support for dependent jobs in enqueue_many * Add module to register dependencies for multiple jobs The get_ready_jobs function will process dependencies for an array of jobs passed in. If any jobs' dependencies are already met, those jobs are returned so they can be enqueued. * Add check for jobs without dependencies * Remove extra colon in dependencies key This seems like a bug, but if I'm mistaken please let me know. * Add bulk deferred jobs to Redis Need to call queue.enqueue_job to create the job hash in redis. Since all of these jobs are deferred, they won't be added to the queue and processed by a worker. * Revert "Remove extra colon in dependencies key" This reverts commit 5ebf7a35009fcca410c43b9327203915ddfd0628. * Enqueue jobs without dependencies separately Any jobs without dependencies will be enqueued before handling * Fix enqueue_many return value * Rename ready_jobs function * Fix enqueue_many return value * Instantiate job category arrays before if statement * Execute pipe to enqueue jobs with met dependencies * Add tests for enqueue_many with dependencies * Change dependency sorting function name * Use common kwargs dict to create jobs * Remove redundant tests for dependent jobs * Alphebetize imports * Test job with met dependencies using enqueue_many * Fix typo * Format with black * Sort importsmain
parent
ffacdcb675
commit
b756cf82bd
@ -0,0 +1,27 @@
|
|||||||
|
from typing import List
|
||||||
|
|
||||||
|
from redis.client import Pipeline
|
||||||
|
from redis.exceptions import WatchError
|
||||||
|
|
||||||
|
from .job import Job
|
||||||
|
|
||||||
|
|
||||||
|
class Dependency:
|
||||||
|
@classmethod
|
||||||
|
def get_jobs_with_met_dependencies(cls, jobs: List['Job'], pipeline: Pipeline):
|
||||||
|
jobs_with_met_dependencies = []
|
||||||
|
jobs_with_unmet_dependencies = []
|
||||||
|
for job in jobs:
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
pipeline.watch(*[Job.key_for(dependency_id) for dependency_id in job._dependency_ids])
|
||||||
|
job.register_dependency(pipeline=pipeline)
|
||||||
|
if job.dependencies_are_met(pipeline=pipeline):
|
||||||
|
jobs_with_met_dependencies.append(job)
|
||||||
|
else:
|
||||||
|
jobs_with_unmet_dependencies.append(job)
|
||||||
|
pipeline.execute()
|
||||||
|
except WatchError:
|
||||||
|
continue
|
||||||
|
break
|
||||||
|
return jobs_with_met_dependencies, jobs_with_unmet_dependencies
|
Loading…
Reference in New Issue