def create_schedule_tick(self, repository_name, schedule_tick_data):
        check.str_param(repository_name, 'repository_name')
        check.inst_param(schedule_tick_data, 'schedule_tick_data', ScheduleTickData)

        with self.connect() as conn:
            try:
                tick_insert = ScheduleTickTable.insert().values(  # pylint: disable=no-value-for-parameter
                    repository_name=repository_name,
                    schedule_name=schedule_tick_data.schedule_name,
                    status=schedule_tick_data.status.value,
                    timestamp=utc_datetime_from_timestamp(schedule_tick_data.timestamp),
                    tick_body=serialize_dagster_namedtuple(schedule_tick_data),
                )
                result = conn.execute(tick_insert)
                tick_id = result.inserted_primary_key[0]
                return ScheduleTick(tick_id, schedule_tick_data)
            except db.exc.IntegrityError as exc:
                six.raise_from(
                    DagsterInvariantViolationError(
                        'Unable to insert ScheduleTick for schedule {schedule_name} in storage'.format(
                            schedule_name=schedule_tick_data.schedule_name,
                        )
                    ),
                    exc,
                )
Beispiel #2
0
    def get_schedule_ticks(self, schedule_origin_id):
        check.str_param(schedule_origin_id, "schedule_origin_id")

        query = (
            db.select([ScheduleTickTable.c.id, ScheduleTickTable.c.tick_body])
            .select_from(ScheduleTickTable)
            .where(ScheduleTickTable.c.schedule_origin_id == schedule_origin_id)
            .order_by(ScheduleTickTable.c.id.desc())
        )

        rows = self.execute(query)
        return list(
            map(lambda r: ScheduleTick(r[0], deserialize_json_to_dagster_namedtuple(r[1])), rows)
        )
Beispiel #3
0
    def get_schedule_ticks_by_schedule(self, repository, schedule_name):
        check.inst_param(repository, 'repository', RepositoryDefinition)
        check.str_param(schedule_name, 'schedule_name')

        query = (db.select([
            ScheduleTickTable.c.id, ScheduleTickTable.c.tick_body
        ]).select_from(ScheduleTickTable).where(
            ScheduleTickTable.c.repository_name == repository.name).where(
                ScheduleTickTable.c.schedule_name == schedule_name))

        rows = self.execute(query)
        return list(
            map(
                lambda r: ScheduleTick(
                    r[0], deserialize_json_to_dagster_namedtuple(r[1])), rows))
Beispiel #4
0
    def get_latest_tick(self, schedule_origin_id):
        check.str_param(schedule_origin_id, "schedule_origin_id")

        query = (
            db.select([ScheduleTickTable.c.id, ScheduleTickTable.c.tick_body])
            .select_from(ScheduleTickTable)
            .where(ScheduleTickTable.c.schedule_origin_id == schedule_origin_id)
            .order_by(ScheduleTickTable.c.timestamp.desc())
            .limit(1)
        )

        rows = self.execute(query)

        if len(rows) == 0:
            return None

        return ScheduleTick(rows[0][0], deserialize_json_to_dagster_namedtuple(rows[0][1]))