def delete_schedule(self, workflow): """Delete schedule config for a given workflow. Args: workflow: The workflow name where the job is defined. """ path = Path(workflow=workflow) self._delete_config(path.get_schedule_path())
def delete_job(self, workflow, job): """Delete config for a given job. Args: workflow: The workflow name where the job is defined. job: The name of the job whose config should be deleted. """ path = Path(workflow=workflow, job=job) self._delete_config(path.get_job_path())
def put_job(self, job_config): """Add or replace a job. Args: job_config: The job config to add or replace. """ path = Path(workflow=job_config.workflow, job=job_config.job) job_config_json = Repository._json_pretty_print(job_config.format()) self._put_config(path.get_job_path(), job_config_json)
def put_schedule(self, schedule_config): """Add or replace a workflow schedule. Args: schedule_config: The schedule config to add or replace. """ path = Path(workflow=schedule_config.workflow) schedule_config_json = Repository._json_pretty_print( schedule_config.format()) self._put_config(path.get_schedule_path(), schedule_config_json)
def get_schedule(self, workflow): """Retrieve schedule config for a given workflow. Args: workflow: The workflow name whose schedule should be retrieved. Returns: The schedule config. """ path = Path(workflow=workflow) schedule_json = self._get_config(path.get_schedule_path()) return WorkflowScheduleConfig.from_json(schedule_json)
def get_job(self, workflow, job): """Retrieve config for a given job. Args: workflow: The workflow name where the job is defined. job: The name of the job whose config should be retrieved. Returns: The job config. """ path = Path(workflow=workflow, job=job) job_json = self._get_config(path.get_job_path()) return JobConfig.from_json(job_json)
def get_job_names(self, workflow): """Retrieve names of all jobs in a given workflow. Returns: List of job names. """ result = [] path = Path(workflow=workflow) workflow_prefix = path.get_workflow_prefix() # It happens that user create a workflow and run a few days, # and then delete them. To adaptive this case, we allow the # workflow doesn't exists even there is token in PAL. self._list_directory(workflow_prefix, True) job_prefix = path.get_job_prefix() jobs = self._list_directory(job_prefix, True) for job in jobs: if job[-1] == Path.DELIMITER: raise PinballException('found unexpected dir in jobs ' 'directory %s' % job_prefix) result.append(job) return result
def test_job_path(self): path = Path(workflow='some_workflow', job='some_job') self.assertEqual('/workflow/some_workflow/job/some_job', path.get_job_path())
def test_schedule_path(self): path = Path(workflow='some_workflow') self.assertEqual('/workflow/some_workflow/schedule', path.get_schedule_path())
def test_workflow_prefix(self): path = Path(workflow='some_workflow') self.assertEqual('/workflow/some_workflow/', path.get_workflow_prefix())