Coordinate the running of periodic tasks in multiple web processes

This PR fixes #2557 by using a DB lock to ensure that only one web worker runs the DB self checks.