Skip to content

Commit 7a8df0b

Browse files
authored
Merge pull request #3778 from camptocamp/with_for_update_limit
Only lock the picked job during the queue selection
2 parents 96b9049 + b2ab048 commit 7a8df0b

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

tilecloud_chain/store/postgresql.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,8 @@ async def _maintenance(self) -> None:
640640
select(Job)
641641
.with_for_update(of=Job, skip_locked=True)
642642
.where(Job.status == _STATUS_CREATED)
643-
.order_by(Job.created_at),
643+
.order_by(Job.created_at)
644+
.limit(1),
644645
)
645646
job = result.scalar()
646647
if job is not None:
@@ -749,7 +750,8 @@ async def list(self) -> AsyncIterator[Tile]:
749750
.join(Job, Queue.job_id == Job.id)
750751
.with_for_update(of=Queue, skip_locked=True)
751752
.order_by(Job.created_at.asc(), Queue.id.asc())
752-
.where(and_(Queue.status == _STATUS_CREATED, Job.status == _STATUS_STARTED)),
753+
.where(and_(Queue.status == _STATUS_CREATED, Job.status == _STATUS_STARTED))
754+
.limit(1),
753755
)
754756
sqlalchemy_tile = result.scalar()
755757
if sqlalchemy_tile is None:

0 commit comments

Comments
 (0)