def exists(task_id): """True if the task exists.""" try: db.task_get(task_id) return True except db.TaskNotFound: return False
def run(task_id): """Runs the task with task id. Underlying method will receive two kwargs: task_id = id of the current task for updating progress = last progress passed to task_update""" task = db.task_get(task_id) if task['is_member']: method = getattr(task['args'][0], task['method']) else: method = task['method'] db.task_start(task_id) return method(task_id=task['id'], progress=task['progress'], *task['args'], **task['kwargs'])
def is_complete(task_id): """Completed if the task is done.""" try: return db.task_get(task_id)['completed_at'] is not None except db.TaskNotFound: return False
def is_active(task_id): """True if the task is active.""" try: return db.task_get(task_id)['is_active'] except db.TaskNotFound: return False
def get(task_id): """Get task from id.""" return db.task_get(task_id)