Exemple #1
0
    def _transform_and_enrich_db_schedule(
        self,
        db_session: Session,
        schedule_record: schemas.ScheduleRecord,
        include_last_run: bool = False,
        include_credentials: bool = False,
    ) -> schemas.ScheduleOutput:
        schedule_dict = schedule_record.dict()
        schedule_dict["labels"] = {
            label["name"]: label["value"]
            for label in schedule_dict["labels"]
        }
        schedule = schemas.ScheduleOutput(**schedule_dict)

        job_id = self._resolve_job_id(schedule_record.project,
                                      schedule_record.name)
        job = self._scheduler.get_job(job_id)
        if job:
            schedule.next_run_time = job.next_run_time

        if include_last_run:
            self._enrich_schedule_with_last_run(db_session, schedule)

        if include_credentials:
            self._enrich_schedule_with_credentials(schedule)

        return schedule
Exemple #2
0
 def get_schedule(
     self, project: str, name: str, include_last_run: bool = False
 ) -> schemas.ScheduleOutput:
     project = project or default_project
     path = f"projects/{project}/schedules/{name}"
     error_message = f"Failed getting schedule for {project}/{name}"
     resp = self.api_call(
         "GET", path, error_message, params={"include_last_run": include_last_run}
     )
     return schemas.ScheduleOutput(**resp.json())
Exemple #3
0
    def _transform_and_enrich_db_schedule(
        self,
        db_session: Session,
        schedule_record: schemas.ScheduleRecord,
        include_last_run: bool = False,
    ) -> schemas.ScheduleOutput:
        schedule = schemas.ScheduleOutput(**schedule_record.dict())

        job_id = self._resolve_job_id(schedule_record.project, schedule_record.name)
        job = self._scheduler.get_job(job_id)
        schedule.next_run_time = job.next_run_time

        if include_last_run:
            schedule = self._enrich_schedule_with_last_run(db_session, schedule)

        return schedule