Esempio n. 1
0
def process_task(config: ConfigHolder, task: Task,
                 session: sqlalchemy.orm.Session):
    try:
        task.status = Task.STATUS_OPTIONS.PROCESSING
        session.commit()
        for subtask in tqdm.tqdm(task.children,
                                 desc=f"Task {task.id}: Processing subtasks"):
            if subtask.status not in [
                    Task.STATUS_OPTIONS.ERROR, Task.STATUS_OPTIONS.INTERRUPTED,
                    Task.STATUS_OPTIONS.FINISHED
            ]:
                subconfig = ConfigHolder(subtask)
                if config.local:
                    subconfig.local = True
                process_task(subconfig, subtask, session)
        to_process = [job for job in task.jobs if job.solution is None]
        process_jobs(to_process, config, session)
        task.status = Task.STATUS_OPTIONS.FINISHED
    except Exception as e:
        print(e)
        to_process = [job for job in task.jobs if job.solution is None]
        if str(e).lower(
        ) != "Backend does not support on_message callback".lower(
        ) and to_process:
            task.status = Task.STATUS_OPTIONS.ERROR
            task.error_message = str(e)
            if is_debug_env():
                raise e
        else:
            task.status = Task.STATUS_OPTIONS.FINISHED
    finally:
        session.commit()
Esempio n. 2
0
def process_task(config: ConfigHolder, task: Task, session: sqlalchemy.orm.Session):
    try:
        task.status = Task.STATUS_OPTIONS.PROCESSING
        session.commit()
        for subtask in tqdm.tqdm(task.children, desc=f"Task {task.id}: Processing subtasks"):
            if subtask.status not in [Task.STATUS_OPTIONS.ERROR, Task.STATUS_OPTIONS.INTERRUPTED, Task.STATUS_OPTIONS.PROCESSING, Task.STATUS_OPTIONS.FINISHED]:
                process_task(ConfigHolder(subtask), subtask, session)
        to_process = [job for job in task.jobs if job.solution is None]
        process_jobs(to_process, config, session)
        task.status = Task.STATUS_OPTIONS.FINISHED
        session.commit()
    except Exception as e:
        print(e)
        task.status = Task.STATUS_OPTIONS.ERROR
        task.error_message = str(e)
        session.commit()