def get_task(self, taskid=None):
"""Returns a dictionary of task details identified by the id
specified. If no id is specified, then the current task is
detected and returned.
"""
if taskid is None:
# assume default
taskid = self.taskid
if not isinstance(taskid, int):
try:
taskid = int(taskid)
except (ValueError, TypeError):
# can't be typecasted to an integer
return {}
if taskid <= 0:
# No task defined
return {}
# Precompile Regulare Expression for Speed
task_re = re.compile('^%s%s%d_([A-Z0-9_]+)$' % (
SCHEDULER_ENVIRO_ID,
TASK_ENVIRO_ID,
taskid,
))
self.logger.debug('Looking for %s%s%d_([A-Z0-9_]+)$' % (
SCHEDULER_ENVIRO_ID,
TASK_ENVIRO_ID,
taskid,
))
# Fetch Task related content
return dict([(task_re.match(k).group(1), v.strip()) \
for (k, v) in environ.items() if task_re.match(k)])
评论列表
文章目录