-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HC-205: improve job revocation mechanism and bug fixes (#17)
* refactor revoke to include recording of revoked task id; fix bug * retrieve uuid correctly * remove sleeps and utilize exponential backoff instead * initialize redis pool
- Loading branch information
Showing
3 changed files
with
75 additions
and
26 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
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
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,39 @@ | ||
#!/bin/env python | ||
import backoff | ||
from redis import BlockingConnectionPool, StrictRedis, RedisError | ||
|
||
from hysds.celery import app | ||
|
||
|
||
REVOKED_TASK_POOL = None | ||
REVOKED_TASK_TMPL = "hysds-revoked-task-%s" | ||
|
||
|
||
def set_redis_revoked_task_pool(): | ||
"""Set redis connection pool for worker status.""" | ||
|
||
global REVOKED_TASK_POOL | ||
if REVOKED_TASK_POOL is None: | ||
REVOKED_TASK_POOL = BlockingConnectionPool.from_url( | ||
app.conf.REDIS_JOB_STATUS_URL) | ||
|
||
|
||
@backoff.on_exception(backoff.expo, | ||
RedisError, | ||
max_tries=10, | ||
max_value=64) | ||
def revoke(task_id, state): | ||
"""Revoke task.""" | ||
|
||
# set redis pool | ||
set_redis_revoked_task_pool() | ||
global REVOKED_TASK_POOL | ||
|
||
# record revoked task | ||
r = StrictRedis(connection_pool=REVOKED_TASK_POOL) | ||
r.setex(REVOKED_TASK_TMPL % task_id, | ||
app.conf.HYSDS_JOB_STATUS_EXPIRES, | ||
state) | ||
|
||
# revoke task | ||
app.control.revoke(task_id, terminate=True) |