Example #1
0
    def mock_bundle_checkin(self, bundle, worker_id, user_id=None):
        """Mock a worker checking in with the latest state of a bundle.

        Args:
            bundle: Bundle to check in.
            worker_id ([type]): worker id of the worker that performs the checkin.
            user_id (optional): user id that performs the checkin. Defaults to the default user id.
        """
        worker_run = BundleCheckinState(
            uuid=bundle.uuid,
            run_status="",
            bundle_start_time=0,
            container_time_total=0,
            container_time_user=0,
            container_time_system=0,
            docker_image="",
            state=bundle.state,
            remote="",
            exitcode=0,
            failure_message="",
            cpu_usage=0.0,
            memory_limit=0,
        )
        self.bundle_manager._model.bundle_checkin(bundle, worker_run, user_id
                                                  or self.user_id, worker_id)
def checkin(worker_id):
    """
    Checks in with the bundle service, storing information about the worker.
    Waits for a message for the worker for WAIT_TIME_SECS seconds. Returns the
    message or None if there isn't one.
    """
    WAIT_TIME_SECS = 3.0

    # Old workers might not have all the fields, so allow subsets to be missing.
    socket_id = local.worker_model.worker_checkin(
        request.user.user_id,
        worker_id,
        request.json.get("tag"),
        request.json.get("group_name"),
        request.json.get("cpus"),
        request.json.get("gpus"),
        request.json.get("memory_bytes"),
        request.json.get("free_disk_bytes"),
        request.json["dependencies"],
        request.json.get("shared_file_system", False),
        request.json.get("tag_exclusive", False),
        request.json.get("exit_after_num_runs", DEFAULT_EXIT_AFTER_NUM_RUNS),
        request.json.get("is_terminating", False),
    )

    for run in request.json["runs"]:
        try:
            worker_run = BundleCheckinState.from_dict(run)
            bundle = local.model.get_bundle(worker_run.uuid)
            local.model.bundle_checkin(bundle, worker_run, request.user.user_id, worker_id)
        except Exception:
            pass

    with closing(local.worker_model.start_listening(socket_id)) as sock:
        return local.worker_model.get_json_message(sock, WAIT_TIME_SECS)
Example #3
0
    def mock_bundle_checkin(self, bundle, worker_id, user_id=None):
        """Mock a worker checking in with the latest state of a bundle.

        Args:
            bundle: Bundle to check in.
            worker_id ([type]): worker id of the worker that performs the checkin.
            user_id (optional): user id that performs the checkin. Defaults to the default user id.
        """
        worker_run = BundleCheckinState(
            uuid=bundle.uuid,
            run_status="",
            bundle_start_time=0,
            container_time_total=0,
            container_time_user=0,
            container_time_system=0,
            docker_image="",
            state=bundle.state,
            remote="",
            exitcode=0,
            failure_message="",
            cpu_usage=0.0,
            memory_usage=0.0,
            bundle_profile_stats={
                RunStage.PREPARING: {
                    'start': 15,
                    'end': 20,
                    'elapsed': 5
                },
                RunStage.RUNNING: {
                    'start': 15,
                    'end': 20,
                    'elapsed': 5
                },
                RunStage.CLEANING_UP: {
                    'start': 15,
                    'end': 20,
                    'elapsed': 5
                },
                RunStage.UPLOADING_RESULTS: {
                    'start': 15,
                    'end': 20,
                    'elapsed': 5
                },
                RunStage.FINALIZING: {
                    'start': 15,
                    'end': 20,
                    'elapsed': 5
                },
            },
        )
        self.bundle_manager._model.bundle_checkin(bundle, worker_run, user_id
                                                  or self.user_id, worker_id)