def run_task(task): db = Database(TASK_MANAGER_NAME) db.job = db.use_coll(TASK_COLL) if run_or_die(task) is True: class_action = task["action"].capitalize() j = class_action(task["name"]) j.run_job() last_run, next_run = refresh_task(task['next_run'], task['repeat']) db.job.update({"_id":task["_id"]}, {"$inc": {"nb_run": 1}}) if j is False: db.job.update({"_id":task["_id"]}, {"$set":{"status":j.status}}) db.job.update({"_id":task["_id"]}, {"$set":{"next_run":None}}) else: db.job.update({"_id":task["_id"]}, {"$set":{"last_run":last_run,"next_run":next_run}}) return True else: return False
def scheduler(): db = Database(TASK_MANAGER_NAME) db.job = db.use_coll(TASK_COLL) for n in db.job.find(): print run_task(n)