Queue in php and postgres

后端 未结 3 1777
太阳男子
太阳男子 2021-01-22 06:37

I would like to find out a good way to go about implementing a jobs queue using postgres and PDO (php).

Basically I have an even

3条回答
  •  不知归路
    2021-01-22 07:30

    As written, another worker trying to claim the job would block at query 1. It can see the old version of the row, but cannot update it--it would block.

    So don't do it in a single transaction. Claim and commit; do the work; then resolve and commit. Any workers coming along will see that the row is already claimed. Also, you can see that it is claimed, which will help you in debugging and monitoring.

    When you claim the row you should mark with something distinctive (a pid, if there only one worker machine, or a hostname and pid, if there are several) rather than simply with 'ongoing'. That way if a worker dies you can manually clean up after it.

提交回复
热议问题