fix: Dependency list in depends_on (#1843)

* test: Dependency list in depends_on

Signed-off-by: Simó Albert i Beltran <sim6@bona.gent>

* fix: Dependency list in depends_on

Signed-off-by: Simó Albert i Beltran <sim6@bona.gent>

---------

Signed-off-by: Simó Albert i Beltran <sim6@bona.gent>
main
Simó Albert i Beltran 2 years ago committed by GitHub
parent 1fa6ec1055
commit ed59b9248a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -254,12 +254,17 @@ class Job:
# dependency could be job instance or id, or iterable thereof # dependency could be job instance or id, or iterable thereof
if depends_on is not None: if depends_on is not None:
if isinstance(depends_on, Dependency): depends_on = ensure_list(depends_on)
job.enqueue_at_front = depends_on.enqueue_at_front depends_on_list = []
job.allow_dependency_failures = depends_on.allow_failure for depends_on_item in depends_on:
depends_on_list = depends_on.dependencies if isinstance(depends_on_item, Dependency):
# If a Dependency has enqueue_at_front or allow_failure set to True, these behaviors are used for
# all dependencies.
job.enqueue_at_front = job.enqueue_at_front or depends_on_item.enqueue_at_front
job.allow_dependency_failures = job.allow_dependency_failures or depends_on_item.allow_failure
depends_on_list.extend(depends_on_item.dependencies)
else: else:
depends_on_list = ensure_list(depends_on) depends_on_list.extend(ensure_list(depends_on_item))
job._dependency_ids = [dep.id if isinstance(dep, Job) else dep for dep in depends_on_list] job._dependency_ids = [dep.id if isinstance(dep, Job) else dep for dep in depends_on_list]
return job return job

@ -117,6 +117,19 @@ class TestDependencies(RQTestCase):
self.assertEqual(q.job_ids, ["fake_job_id_2", "fake_job_id_1"]) self.assertEqual(q.job_ids, ["fake_job_id_2", "fake_job_id_1"])
def test_dependency_list_in_depends_on(self):
"""Enqueue with Dependency list in depends_on"""
q = Queue(connection=self.testconn)
w = SimpleWorker([q], connection=q.connection)
# enqueue dependent job when parent successfully finishes
parent_job1 = q.enqueue(say_hello)
parent_job2 = q.enqueue(say_hello)
job = q.enqueue_call(say_hello, depends_on=[Dependency([parent_job1]), Dependency([parent_job2])])
w.work(burst=True)
self.assertEqual(job.get_status(), JobStatus.FINISHED)
def test_dependencies_are_met_if_parent_is_canceled(self): def test_dependencies_are_met_if_parent_is_canceled(self):
"""When parent job is canceled, it should be treated as failed""" """When parent job is canceled, it should be treated as failed"""
queue = Queue(connection=self.testconn) queue = Queue(connection=self.testconn)

Loading…
Cancel
Save