Re:Do you really need Redis? How to get away with just Postg...
by edwinyzh on Saturday June 12, 2021 @04:52AM
(#27482878)
Great! So I learned this technique. But one thing that's not clear to me - how a "expired" datetime field can allow easy retries? Anyone give me an example? Thanks!
[ Parent
| on HN ]
Re:Do you really need Redis? How to get away with just Postg...
by chx on Saturday June 12, 2021 @05:14AM
(#27482979)
Successful items are deleted from the queue before they expire. So an item with expired > current time needs to be retried because it failed processing. So, a cronjob resets these to expire 0 and the next worker can pick them up.
Re:Do you really need Redis? How to get away with just Postg...
by johbjo on Saturday June 12, 2021 @12:51PM
(#27485680)
Could the process not delete the row, and not commit until it has finished processing? Otherwise, the transaction is rolled back when the db connection ends. This would not require timeout or clean-up.
One would need the appropriate transaction isolation, but shouldn't it work?
Re:Do you really need Redis? How to get away with just Postg...
by Seattle3503 on Saturday June 12, 2021 @07:03PM
(#27488168)
That's requires maintaining more db locks.
Re:Do you really need Redis? How to get away with just Postg...
by layoutIfNeeded on Saturday June 12, 2021 @06:49AM
(#27483500)
Doesn’t sound like a robust solution. What if the job takes longer than your estimated expire time? Does the worker keep updating the expiry date on a background thread while doing the processing?
Re:Do you really need Redis? How to get away with just Postg...
by cbo100 on Saturday June 12, 2021 @08:29AM
(#27483991)
Same for any queuing system. You need to set the expiry time long enough for the expected task duration.
In SQS, for example, you use a visibility timeout set high enough that you will have time to finish the job and delete the message before SQS hand it off to another reader.
You won’t always finish in time though, so ideally jobs are idempotent.
Re:Do you really need Redis? How to get away with just Postg...
by edwinyzh on Saturday June 12, 2021 @06:43AM
(#27483470)
Thanks for the explanation and time is needed in order to digest it... I guess one might start with the simple "status" field approach ;)
Re:Do you really need Redis? How to get away with just Postg...
by DangitBobby on Saturday June 12, 2021 @11:58AM
(#27485311)
The status doesn't help if the worker died during processing. If you've got something that's been "in progress" for 20 minutes of a job that takes 2, your job might not be getting done. That's what expired is for.