diff --git a/rq/job.py b/rq/job.py index 81ed98e..0dcbf28 100644 --- a/rq/job.py +++ b/rq/job.py @@ -254,12 +254,17 @@ class Job: # dependency could be job instance or id, or iterable thereof if depends_on is not None: - if isinstance(depends_on, Dependency): - job.enqueue_at_front = depends_on.enqueue_at_front - job.allow_dependency_failures = depends_on.allow_failure - depends_on_list = depends_on.dependencies - else: - depends_on_list = ensure_list(depends_on) + depends_on = ensure_list(depends_on) + depends_on_list = [] + for depends_on_item in depends_on: + 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: + 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] return job diff --git a/tests/test_dependencies.py b/tests/test_dependencies.py index 26b115d..980e805 100644 --- a/tests/test_dependencies.py +++ b/tests/test_dependencies.py @@ -117,6 +117,19 @@ class TestDependencies(RQTestCase): 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): """When parent job is canceled, it should be treated as failed""" queue = Queue(connection=self.testconn)