Exemple #1
0
def discard_subtasks(
    work_dir: dirutils.RequestorTaskDir,
    subtask_ids: List[str],
) -> List[str]:
    task_manager = DBTaskManager(work_dir)
    for subtask_id in subtask_ids:
        task_manager.update_subtask_status(subtask_id, SubtaskStatus.ABORTED)
    return subtask_ids
Exemple #2
0
async def verify(
        work_dir: dirutils.RequestorTaskDir,
        subtask_id: str,
) -> Tuple[enums.VerifyResult, Optional[str]]:
    with open(work_dir / 'task_params.json', 'r') as f:
        task_params = json.load(f)
    with open(work_dir / f'subtask{subtask_id}.json', 'r') as f:
        params = json.load(f)
    subtask_work_dir = work_dir / f'subtask{subtask_id}'
    subtask_work_dir.mkdir()
    subtask_results_dir = subtask_work_dir / 'results'
    subtask_results_dir.mkdir()
    subtask_output_dir = subtask_work_dir / 'output'
    subtask_output_dir.mkdir()

    subtask_outputs_dir = work_dir.subtask_outputs_dir(subtask_id)
    zip_file_path = subtask_outputs_dir / f'{subtask_id}.zip'
    with zipfile.ZipFile(zip_file_path, 'r') as zip_file:
        zip_file.extractall(subtask_results_dir)

    task_manager = DBTaskManager(work_dir)
    part_num = task_manager.get_part_num(subtask_id)
    task_manager.update_subtask_status(subtask_id, SubtaskStatus.VERIFYING)
    dir_contents = subtask_results_dir.iterdir()

    verdict = await verifier.verify(
        [str(entry) for entry in dir_contents if entry.is_file()],
        params['borders'],
        work_dir.task_inputs_dir / params['scene_file'],
        params['resolution'],
        params['samples'],
        params['frames'],
        params['output_format'],
        mounted_paths={
            'OUTPUT_DIR': str(subtask_output_dir),
            'WORK_DIR': str(subtask_work_dir),
        }
    )
    print("Verdict:", verdict)
    if not verdict:
        task_manager.update_subtask_status(
            subtask_id,
            SubtaskStatus.FAILURE)
        # pylint: disable=fixme
        # TODO: provide some extra info why verification failed
        return enums.VerifyResult.FAILURE, None

    task_manager.update_subtask_status(subtask_id, SubtaskStatus.SUCCESS)
    _collect_results(
        task_manager,
        part_num,
        task_params,
        params,
        work_dir,
        subtask_results_dir,
        work_dir.task_outputs_dir,
    )
    return enums.VerifyResult.SUCCESS, None