If you're working with Ruby I have had good experiences with Que[1], which implements a pattern similar to the OP using advisory locks.
https://github.com/timgit/pg-boss for node, https://github.com/mbuhot/ecto_job for elixir.
I wish all these libraries agreed on a common schema >_<