Several fixes to reduce cases of stuck jobs

Due to the locking mechanism we have, that prevents same query from being executed more than once at a time, some queries might get into a "limbo" state and stop being executed until the lock is manually removed.

This pull request adds some fixes to reduce (eliminate?) those cases:

1. Set expiry time to locks (default: 12 hours).
2. If lock found is of a "ready" job (finished, revoked or failed), ignore it and execute a new job.
3. Cleanup job that removes locks of non existing tasks (might happen after cold restart of the worker).