diff --git a/landoapi/models/landing_job.py b/landoapi/models/landing_job.py index 91708e91..48207a63 100644 --- a/landoapi/models/landing_job.py +++ b/landoapi/models/landing_job.py @@ -248,11 +248,7 @@ def job_queue_query( grace_cutoff = now - datetime.timedelta(seconds=grace_seconds) q = q.filter(cls.created_at < grace_cutoff) - # Any `LandingJobStatus.IN_PROGRESS` job is first and there should - # be a maximum of one (per repository). For - # `LandingJobStatus.SUBMITTED` jobs, higher priority items come first - # and then we order by creation time (older first). - q = q.order_by(cls.status.desc(), cls.priority.desc(), cls.created_at) + q = q.order_by(cls.priority.desc(), cls.status.desc(), cls.created_at) return q @@ -376,6 +372,8 @@ def transition_status( if action in (LandingJobAction.FAIL, LandingJobAction.DEFER): self.error = kwargs["message"] + if action == LandingJobAction.DEFER: + self.priority -= 1 if action == LandingJobAction.LAND: self.landed_commit_id = kwargs["commit_id"] diff --git a/tests/test_landings.py b/tests/test_landings.py index 6d03f077..27613eef 100644 --- a/tests/test_landings.py +++ b/tests/test_landings.py @@ -399,6 +399,7 @@ def test_lose_push_race( assert not worker.run_job(job, repo, hgrepo, treestatus) assert job.status == LandingJobStatus.DEFERRED + assert job.priority == -1 def test_failed_landing_job_notification(