Beispiel #1
0
def execute_task(id):
    session = Session()
    task = session.query(Task).get(id)
    logger.debug("Processing task with ID: {}", id)
    task_uid = task.task_id
    task_module = importlib.import_module("chronos.tasks.{}".format(task_uid))
    task_id_dict = {"task_id": id}

    logger.debug("Starting task with ID: {}", id)
    task.time_started = datetime.datetime.now()
    task.status = "STARTED"
    session.commit()

    event.trigger("task_started", task_id_dict)
    arguments = {**json.loads(task.task_arguments), **task_id_dict}

    task.output = task_module.run(json.dumps(arguments), event)

    event.trigger("task_finished", task_id_dict)

    task.time_finished = datetime.datetime.now()
    task.status = "FINISHED"
    session.commit()
    logger.debug("Finished task with ID: {}", id)

    session.close()

    return
Beispiel #2
0
    def enable(self):
        session = Session()
        script_from_database = session.query(ScriptModel).get(self.uid)
        script_from_database.enabled = True
        session.commit()
        session.close()

        self.enabled = True

        event.trigger("script_updated", self.__dict__())
        event.trigger("action_complete", {"action": "enable", "uid": self.uid})
Beispiel #3
0
def dispatch_task(task_id, task_arguments, task_priority="ROUTINE"):
    session = Session()
    task = Task(
        task_id=task_id,
        task_arguments=json.dumps(task_arguments),
        priority=task_priority,
        status="WAITING",
    )

    session.add(task)
    session.commit()
    logger.debug("Dispatched task: {}", task_id)
    event.trigger("task_dispatched", {"task_id": task_id})

    session.close()

    return True
Beispiel #4
0
def test():
    event.trigger("test")