Beispiel #1
0
 def tick(self):
     # TODO: use asyncio \ aiohttp instead of sequential requests
     # TODO: handle errors
     for host, per_host_info in self._per_host_info.items():
         assert isinstance(per_host_info, TaskOnHostExecutionInfo)
         client = WorkerApiClient(worker_host=host)
         if per_host_info.task_id is None:
             per_host_info.task_id = client.create_task(self.task.task_struct.to_json())
             per_host_info.state.change_state('idle', force=True)
             self._save_to_backend()
         if per_host_info.state.name == TaskState.idle:
             per_host_info.state.change_state(client.start_task(per_host_info.task_id).name, force=True)
             self._save_to_backend()
         if not per_host_info.state.is_terminal:
             new_state_name = client.get_task_state(per_host_info.task_id).name
             if new_state_name != per_host_info.state.name:
                 per_host_info.state.change_state(new_state_name, force=True)
                 self._save_to_backend()
             if per_host_info.state.is_failed:
                 break
Beispiel #2
0
def main():
    # http POST :8080/v1.0/task/
    cli = WorkerApiClient(worker_host="localhost", worker_port=8081)
    task_id = cli.create_task(task_struct=json.load(open("worker/tests/sample_task.json")))
    print(task_id)
    task_state = cli.start_task(task_id)
    print(task_state.name)
    while True:
        sleep(1)
        task_state = cli.get_task_state(task_id)
        print(task_state.name)
        if task_state.is_terminal:
            print("Out:")
            print(cli.get_task_log(task_id, "out"), end="")
            print("Err:")
            print(cli.get_task_log(task_id, "err"), end="")
            break