Esempio n. 1
0
def _create_jobs(jobs: List[Dict[str, Any]],
                 api_client: ApiClient) -> Dict[str, int]:
    deployment_data = {}
    for job in jobs:
        dbx_echo(f'Processing deployment for job: {job["name"]}')
        jobs_service = JobsService(api_client)
        all_jobs = jobs_service.list_jobs().get("jobs", [])
        matching_jobs = [
            j for j in all_jobs if j["settings"]["name"] == job["name"]
        ]

        if not matching_jobs:
            job_id = _create_job(api_client, job)
        else:

            if len(matching_jobs) > 1:
                raise Exception(
                    f"""There are more than one jobs with name {job["name"]}.
                Please delete duplicated jobs first""")

            job_id = matching_jobs[0]["job_id"]
            _update_job(jobs_service, job_id, job)

        deployment_data[job["name"]] = job_id
    return deployment_data
Esempio n. 2
0
    def launch(self) -> Tuple[Dict[Any, Any], Optional[str]]:
        dbx_echo("Launching job via run now API")
        jobs_service = JobsService(self.api_client)

        all_jobs = jobs_service.list_jobs().get("jobs", [])

        matching_jobs = [
            j for j in all_jobs if j["settings"]["name"] == self.job
        ]

        if not matching_jobs:
            raise Exception(f"Job with name {self.job} not found")

        if len(matching_jobs) > 1:
            raise Exception(
                f"Job with name {self.job} is duplicated. Please make job name unique."
            )

        job_data = matching_jobs[0]
        job_id = job_data["job_id"]

        active_runs = jobs_service.list_runs(job_id,
                                             active_only=True).get("runs", [])

        for run in active_runs:
            if self.existing_runs == "pass":
                dbx_echo("Passing the existing runs status check")

            if self.existing_runs == "wait":
                dbx_echo(
                    f'Waiting for job run with id {run["run_id"]} to be finished'
                )
                _wait_run(self.api_client, run)

            if self.existing_runs == "cancel":
                dbx_echo(f'Cancelling run with id {run["run_id"]}')
                _cancel_run(self.api_client, run)

        if self.prepared_parameters:
            dbx_echo(
                f"Default launch parameters are overridden with the following: {self.prepared_parameters}"
            )
            # we don't do a null-check here since the job existence will be already done during listing above.
            job_settings = job_data.get("settings")

            # here we define the job type to correctly pass parameters
            extra_payload_key = _define_payload_key(job_settings)

            extra_payload = {extra_payload_key: self.prepared_parameters}

            run_data = jobs_service.run_now(job_id, **extra_payload)

        else:
            run_data = jobs_service.run_now(job_id)

        return run_data, job_id
Esempio n. 3
0
    def launch(self) -> Tuple[Dict[Any, Any], Optional[str]]:
        dbx_echo("Launching job via run now API")
        jobs_service = JobsService(self.api_client)

        all_jobs = jobs_service.list_jobs().get("jobs", [])

        matching_jobs = [
            j for j in all_jobs if j["settings"]["name"] == self.job
        ]

        if not matching_jobs:
            raise Exception(f"Job with name {self.job} not found")

        if len(matching_jobs) > 1:
            raise Exception(
                f"Job with name {self.job} is duplicated. Please make job name unique."
            )

        job_id = matching_jobs[0]["job_id"]

        active_runs = jobs_service.list_runs(job_id,
                                             active_only=True).get("runs", [])

        for run in active_runs:
            if self.existing_runs == "pass":
                dbx_echo("Passing the existing runs status check")

            if self.existing_runs == "wait":
                dbx_echo(
                    f'Waiting for job run with id {run["run_id"]} to be finished'
                )
                _wait_run(self.api_client, run)

            if self.existing_runs == "cancel":
                dbx_echo(f'Cancelling run with id {run["run_id"]}')
                _cancel_run(self.api_client, run)

        if self.override_parameters:
            _prepared_parameters = sum(
                [[k, v] for k, v in self.override_parameters.items()], [])
            dbx_echo(
                f"Default launch parameters are overridden with the following: {_prepared_parameters}"
            )
            run_data = jobs_service.run_now(job_id,
                                            python_params=_prepared_parameters)
        else:
            run_data = jobs_service.run_now(job_id)

        return run_data, job_id