| This looks promising. I'm currently dealing with a queuing-related issue. I have a series of tasks running across servers that consume from a queue and run a task. Often, these tasks die mid-execution (but can be resumed by any other server). So, the queue is a database, and the running tasks "touch" a timestamp in the database if they are still executing. When a database document hasn't been updated for a while, the "consumption query" makes it so that it is 'redelivered' to an available server listening to the "queue". Of course, this is subpar, but we haven't yet come across an elegant (and not too over-engineered) way to replace this. |
It's built into some RDBMS. SQL Server has READPAST [1, 2], so you can do:
And if your process dies midway through, the transaction is rolled back and the row is immediately visible to another worker.[1] https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-tra... READPAST is primarily used to reduce locking contention when implementing a work queue that uses a SQL Server table. A queue reader that uses READPAST skips past queue entries locked by other transactions to the next available queue entry, without having to wait until the other transactions release their locks.
[2] https://docs.microsoft.com/en-us/sql/t-sql/queries/output-cl...