def test_cron_clock_hourly_daylight_savings_time_backward(self, serialize): """ 11/4/2018, at 2am, America/New_York switched clocks back an hour. """ dt = pendulum.datetime(2018, 11, 3, 23, tz="America/New_York") c = clocks.CronClock("0 * * * *", dt) if serialize: c = ClockSchema().load(ClockSchema().dump(c)) next_4 = islice(c.events(after=dt), 4) # repeat the 1am run in local time assert [t.in_tz("America/New_York").hour for t in next_4] == [0, 1, 2, 3] # runs every hour UTC assert [t.in_tz("UTC").hour for t in next_4] == [4, 6, 7, 8]
def test_cron_clock_hourly_daylight_savings_time_forward(self, serialize): """ On 3/11/2018, at 2am, America/New_York switched clocks forward an hour. """ dt = pendulum.datetime(2018, 3, 10, 23, tz="America/New_York") c = clocks.CronClock("0 * * * *", dt) if serialize: c = ClockSchema().load(ClockSchema().dump(c)) next_4 = islice(c.events(after=dt), 4) # skip 2am assert [t.in_tz("America/New_York").hour for t in next_4] == [0, 1, 3, 4] # constant hourly schedule in utc time assert [t.in_tz("UTC").hour for t in next_4] == [5, 6, 7, 8]
def test_cron_clock_daily_start_daylight_savings_time_backward(self, serialize): """ On 11/4/2018, at 2am, America/New_York switched clocks back an hour. Confirm that a schedule for 9am America/New_York stays 9am through the switch. """ dt = pendulum.datetime(2018, 11, 1, 9, tz="America/New_York") c = clocks.CronClock("0 9 * * *", dt) if serialize: c = ClockSchema().load(ClockSchema().dump(c)) next_4 = islice(c.events(after=dt), 4) # constant 9am start assert [t.in_tz("America/New_York").hour for t in next_4] == [9, 9, 9, 9] assert [t.in_tz("UTC").hour for t in next_4] == [13, 13, 14, 14]
def test_interval_clock_daily_start_daylight_savings_time_forward(self, serialize): """ On 3/11/2018, at 2am, America/New_York switched clocks forward an hour. Confirm that a schedule for 9am America/New_York stays 9am through the switch. """ dt = pendulum.datetime(2018, 3, 8, 9, tz="America/New_York") c = clocks.IntervalClock(timedelta(days=1), start_date=dt) if serialize: c = ClockSchema().load(ClockSchema().dump(c)) next_4 = islice(c.events(after=dt), 4) # constant 9am start assert [t.in_tz("America/New_York").hour for t in next_4] == [9, 9, 9, 9] # utc time shifts assert [t.in_tz("UTC").hour for t in next_4] == [14, 14, 13, 13]
async def set_flow_group_schedule(flow_group_id: str, clocks: List[dict]) -> bool: """ Sets a schedule for a flow group Args: - flow_group_id (str): the ID of the flow group to update - clocks (List[dict]): a list of dictionaries defining clocks for the schedule Returns: - bool: whether setting the schedule was successful Raises: - ValueError: if flow group ID isn't provided """ for clock in clocks: try: ClockSchema().load(clock) except: raise ValueError(f"Invalid clock provided for schedule: {clock}") if not flow_group_id: raise ValueError("Invalid flow group ID") result = await models.FlowGroup.where(id=flow_group_id).update( set=dict(schedule=dict(type="Schedule", clocks=clocks)) ) deleted_runs = await models.FlowRun.where( { "flow": {"flow_group_id": {"_eq": flow_group_id}}, "state": {"_eq": "Scheduled"}, "auto_scheduled": {"_eq": True}, } ).delete() return bool(result.affected_rows)
def test_interval_clock_hourly_daylight_savings_time_backward(self, serialize): """ 11/4/2018, at 2am, America/New_York switched clocks back an hour. """ dt = pendulum.datetime(2018, 11, 3, 23, tz="America/New_York") c = clocks.IntervalClock(timedelta(hours=1), start_date=dt) if serialize: c = ClockSchema().load(ClockSchema().dump(c)) next_4 = islice(c.events(after=dt), 4) # repeat the 1am run in local time assert [t.start_time.in_tz("America/New_York").hour for t in next_4] == [ 0, 1, 1, 2, ] # runs every hour UTC assert [t.start_time.in_tz("UTC").hour for t in next_4] == [4, 5, 6, 7]
async def set_flow_group_schedule(flow_group_id: str, clocks: List[dict], timezone: str = None) -> bool: """ Sets a schedule for a flow group Args: - flow_group_id (str): the ID of the flow group to update - clocks (List[dict]): a list of dictionaries defining clocks for the schedule - timezone (str, optional): an optional timezone to set for the schedule Returns: - bool: whether setting the schedule was successful Raises: - ValueError: if flow group ID isn't provided """ if timezone: if timezone not in pendulum.timezones: raise ValueError( f"Invalid timezone provided for schedule: {timezone}") start_date = { "dt": pendulum.now(timezone).naive().to_iso8601_string(), "tz": timezone, } else: start_date = None for clock in clocks: clock["start_date"] = start_date try: ClockSchema().load(clock) except: raise ValueError(f"Invalid clock provided for schedule: {clock}") if not flow_group_id: raise ValueError("Invalid flow group ID") result = await models.FlowGroup.where(id=flow_group_id).update(set=dict( schedule=dict(type="Schedule", clocks=clocks))) # Delete all auto-scheduled runs runs_to_delete = await models.FlowRun.where({ "flow": { "flow_group_id": { "_eq": flow_group_id } }, "state": { "_eq": "Scheduled" }, "auto_scheduled": { "_eq": True }, }).get({"id"}) await asyncio.gather( * [api.runs.delete_flow_run(flow_run.id) for flow_run in runs_to_delete]) return bool(result.affected_rows)
def test_interval_clock_hourly_daylight_savings_time_forward_with_UTC( self, serialize ): """ On 3/11/2018, at 2am, America/New_York switched clocks forward an hour. """ dt = pendulum.datetime(2018, 3, 10, 23, tz="America/New_York") c = clocks.IntervalClock(timedelta(hours=1), start_date=dt.in_tz("UTC")) if serialize: c = ClockSchema().load(ClockSchema().dump(c)) next_4 = islice(c.events(after=dt), 4) # skip 2am assert [t.start_time.in_tz("America/New_York").hour for t in next_4] == [ 0, 1, 3, 4, ] # constant hourly schedule in utc time assert [t.start_time.in_tz("UTC").hour for t in next_4] == [5, 6, 7, 8]