-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.py
63 lines (47 loc) · 1.66 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/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)
def create_info_message_files(msg=None, msg_details=None):
"""
Creates the _alt_msg.txt and _alt_msg_details.txt
files for population into the job status json.
:param msg: The short info message. Can be a list or a string.
Should be shorter than 35 characters.
:param msg_details: The message details.
:return:
"""
if msg:
with open('_alt_msg.txt', 'w') as f:
if isinstance(msg, list):
for m in msg:
f.write("%s\n" % str(m))
else:
f.write("%s\n" % str(msg))
if msg_details:
with open('_alt_msg_details.txt', 'w') as f:
f.write("%s\n" % msg_details)