コード例 #1
0
    def load_worker(worker_id):
        worker = ws.get_worker(worker_id)
        result = worker.__dict__
        if worker.current_task_id:
            task = ats.get_task_by_id(worker.current_task_id)
            if task:
                result['is_assembling'] = True

            else:
                task = lts.get_task_by_id(worker.current_task_id)

            parents = ts.get_assembling_parents(
                worker.current_task_id) if result.get(
                    'is_assembling', False) else ts.get_learning_parents(
                        worker.current_task_id)
            running_task_ids = [
                t_id for t_id, t in parents if t.state == "running"
            ]
            result['task_ids'] = running_task_ids
            if len(running_task_ids) > 1:
                result['is_working_on_multiple_tasks'] = True

            result['log'] = task.log

        return result
コード例 #2
0
ファイル: manage.py プロジェクト: chenyp79/DeepWaterFramework
    def _stop_sub_task(sub_task_id, task_store, assembling):
        sub_task = task_store.get_task_by_id(sub_task_id)
        worker_id = sub_task.assigned_to
        parents = ts.get_assembling_parents(sub_task_id) if assembling else ts.get_learning_parents(sub_task_id)
        if not parents:
            return

        sub_task_changes = sub_task.stop()
        if sub_task_changes:
            task_store.update_task(sub_task_changes, sub_task_id)
            if not sub_task.assigned_to:
                worker = ws.get_worker(worker_id)
                if worker:
                    worker_changes = worker.clear_task()
                    ws.update_worker(worker_changes, worker_id)
コード例 #3
0
def _assign_task(worker_id, task_id, task_store, assembling):
    task = task_store.get_task_by_id(task_id)
    if task.state != "runnable":
        return None, None

    task_changes = task.assign_to(worker_id)
    task_result_id = task_store.update_task(task_changes, task_id)
    parents = ts.get_assembling_parents(
        task_id) if assembling else ts.get_learning_parents(task_id)
    experiment_ids = {p.experiment_id for _, p in parents}
    parent_success = True
    for pt_id, parent in parents:
        p_change = parent.start()
        parent_success = ts.update_task(p_change, pt_id) and parent_success

    return task_id, experiment_ids
コード例 #4
0
ファイル: result.py プロジェクト: chenyp79/DeepWaterFramework
    def persist_result(job_type, task_store, task_id, get_result_func, result):
        try:
            result = get_result_func(result)
            if result:
                experiments = {}
                task = task_store.get_task_by_id(task_id)
                change = task.completed(result)
                success = task_store.update_task(change, task_id)
                parents = ts.get_assembling_parents(
                    task_id
                ) if job_type == "assembling" else ts.get_learning_parents(
                    task_id)
                for p_task_id, p_task in parents:
                    change = p_task.completed(task_id)
                    success = ts.update_task(change, p_task_id) and success
                    if p_task.experiment_id in experiments:
                        exp_sum = experiments[p_task.experiment_id]

                    else:
                        if p_task.learn_task_id:
                            exp = es.get_experiment(p_task.experiment_id)
                            if exp:
                                scheduler.check_experiment(
                                    p_task.experiment_id, exp.priority)

                        exp_sum = ess.get_experiment_summary(
                            p_task.experiment_id)
                        if exp_sum:
                            experiments[p_task.experiment_id] = exp_sum

                    if job_type == "assembling":
                        exp_change = exp_sum.set_assemble_result(
                            p_task_id, result)

                    else:
                        exp_change = exp_sum.set_learn_result(
                            p_task_id, result) if exp_sum else None

                    if exp_change:
                        success = ess.update_experiment_summary(
                            exp_change, p_task.experiment_id) and success

                return bool(success)

        except Exception as e:
            return False
コード例 #5
0
def _remove_task(worker_id, worker):
    try:
        a_task = ats.get_task_by_id(worker.current_task_id)
        if not a_task:
            l_task = lts.get_task_by_id(worker.current_task_id)

        task_changes = (a_task or l_task).revoke_assign_from(worker_id)
        success = ats.update_task(
            task_changes,
            worker.current_task_id) if a_task else lts.update_task(
                task_changes, worker.current_task_id)
        parents = ts.get_assembling_parents(
            worker.current_task_id) if a_task else ts.get_learning_parents(
                worker.current_task_id)
        for pt_id, parent in parents:
            t_change = parent.make_runnable(True)
            success = ts.update_task(t_change, pt_id) and success
            exp = es.get_experiment(parent.experiment_id)
            scheduler.add_experiment(parent.experiment_id, exp.priority)

        return success

    except Exception as e:
        return None