-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rq.contrib.legacy.cleanup_ghosts() function, to clean up old mess.
- Loading branch information
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import logging | ||
from rq import get_current_connection | ||
from rq import Worker | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def cleanup_ghosts(): | ||
""" | ||
RQ versions < 0.3.6 suffered from a race condition where workers, when | ||
abruptly terminated, did not have a chance to clean up their worker | ||
registration, leading to reports of ghosted workers in `rqinfo`. Since | ||
0.3.6, new worker registrations automatically expire, and the worker will | ||
make sure to refresh the registrations as long as it's alive. | ||
This function will clean up any of such legacy ghosted workers. | ||
""" | ||
conn = get_current_connection() | ||
for worker in Worker.all(): | ||
if conn._ttl(worker.key) == -1: | ||
ttl = worker.default_worker_ttl | ||
conn.expire(worker.key, ttl) | ||
logger.info('Marked ghosted worker {0} to expire in {1} seconds.'.format(worker.name, ttl)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters