Esempio n. 1
0
def execute_cursor_command(sensor_name, cli_args, print_fn):
    with DagsterInstance.get() as instance:
        with get_repository_location_from_kwargs(
                instance, version=dagster_version,
                kwargs=cli_args) as repo_location:
            if bool(cli_args.get("delete")) == bool(cli_args.get("set")):
                # must use one of delete/set
                raise click.UsageError(
                    "Must set cursor using `--set <value>` or use `--delete`")

            cursor_value = cli_args.get("set")

            external_repo = get_external_repository_from_repo_location(
                repo_location, cli_args.get("repository"))
            check_repo_and_scheduler(external_repo, instance)
            external_sensor = external_repo.get_external_sensor(sensor_name)
            job_state = instance.get_job_state(
                external_sensor.get_external_origin_id())
            if not job_state:
                instance.add_job_state(
                    JobState(
                        external_sensor.get_external_origin(),
                        JobType.SENSOR,
                        JobStatus.STOPPED,
                        SensorJobData(
                            min_interval=external_sensor.min_interval_seconds,
                            cursor=cursor_value),
                    ))
            else:
                instance.update_job_state(
                    job_state.with_data(
                        SensorJobData(
                            last_tick_timestamp=job_state.job_specific_data.
                            last_tick_timestamp,
                            last_run_key=job_state.job_specific_data.
                            last_run_key,
                            min_interval=external_sensor.min_interval_seconds,
                            cursor=cursor_value,
                        ), ))
            if cursor_value:
                print_fn(
                    f'Set cursor state for sensor {external_sensor.name} to "{cursor_value}"'
                )
            else:
                print_fn(
                    f"Cleared cursor state for sensor {external_sensor.name}")
Esempio n. 2
0
    def get_default_job_state(self, _instance):
        from dagster.core.scheduler.job import JobState, JobStatus, SensorJobData

        return JobState(
            self.get_external_origin(),
            JobType.SENSOR,
            JobStatus.STOPPED,
            SensorJobData(min_interval=self.min_interval_seconds),
        )
Esempio n. 3
0
 def _write(self):
     self._instance.update_job_tick(self._tick)
     if self._tick.status in FULFILLED_TICK_STATES:
         last_run_key = None
         if self._tick.run_keys:
             last_run_key = self._tick.run_keys[-1]
         elif self._job_state.job_specific_data:
             last_run_key = self._job_state.job_specific_data.last_run_key
         self._instance.update_job_state(
             self._job_state.with_data(
                 SensorJobData(self._tick.timestamp, last_run_key)))
Esempio n. 4
0
 def _write(self):
     to_update = self._to_resolve[0] if self._to_resolve else self._tick
     self._instance.update_job_tick(to_update)
     for tick in self._to_resolve[1:]:
         self._instance.create_job_tick(tick.job_tick_data)
     if any([
             tick.status in FULFILLED_TICK_STATES
             for tick in self._to_resolve
     ]):
         self._instance.update_job_state(
             self._job_state.with_data(SensorJobData(self._tick.timestamp)))
Esempio n. 5
0
 def _write(self):
     self._instance.update_job_tick(self._tick)
     if self._tick.status in FULFILLED_TICK_STATES:
         last_run_key = (self._job_state.job_specific_data.last_run_key
                         if self._job_state.job_specific_data else None)
         if self._tick.run_keys:
             last_run_key = self._tick.run_keys[-1]
         self._instance.update_job_state(
             self._job_state.with_data(
                 SensorJobData(
                     last_tick_timestamp=self._tick.timestamp,
                     last_run_key=last_run_key,
                     min_interval=self._external_sensor.
                     min_interval_seconds,
                 )))