コード例 #1
0
 def test_interval_schedule_can_be_exactly_one_minute(self):
     assert schedules.IntervalSchedule(pendulum.now("UTC"),
                                       interval=timedelta(minutes=1))
     assert schedules.IntervalSchedule(pendulum.now("UTC"),
                                       interval=timedelta(seconds=60))
     assert schedules.IntervalSchedule(
         pendulum.now("UTC"), interval=timedelta(microseconds=60000000))
コード例 #2
0
 def test_interval_schedule_interval_must_be_more_than_one_minute(self):
     with pytest.raises(ValueError):
         schedules.IntervalSchedule(pendulum.now("UTC"),
                                    interval=timedelta(seconds=59))
     with pytest.raises(ValueError):
         schedules.IntervalSchedule(
             pendulum.now("UTC"), interval=timedelta(microseconds=59999999))
     with pytest.raises(ValueError):
         schedules.IntervalSchedule(pendulum.now("UTC"),
                                    interval=timedelta(0))
コード例 #3
0
 def test_next_n_with_no_next(self):
     start_date = pendulum.datetime(2018, 1, 1)
     now = pendulum.now("UTC")
     s = schedules.IntervalSchedule(start_date, timedelta(days=1))
     t = schedules.OneTimeSchedule(start_date=now.add(hours=-1))
     main = schedules.UnionSchedule([s, t])
     assert main.next(2) == s.next(2)
コード例 #4
0
 def test_next_n(self):
     start_date = pendulum.datetime(2018, 1, 1)
     now = pendulum.now("UTC")
     s = schedules.IntervalSchedule(start_date, timedelta(days=1))
     t = schedules.OneTimeSchedule(start_date=s.next(1)[0].add(minutes=-1))
     main = schedules.UnionSchedule([s, t])
     assert main.next(2) == [t.next(1)[0], s.next(1)[0]]
コード例 #5
0
ファイル: test_schedules.py プロジェクト: weblearngit/prefect
def test_serialize_interval_at_annual_resolution():
    schedule = schedules.IntervalSchedule(
        start_date=pendulum.now("utc"),
        interval=datetime.timedelta(days=365, microseconds=1),
    )
    schema = schemas.IntervalScheduleSchema()
    serialized = schema.dump(schedule)
    assert serialized["interval"] == 31536000000001
コード例 #6
0
 def test_interval_schedule_end_date(self):
     start_date = pendulum.datetime(2018, 1, 1)
     end_date = pendulum.datetime(2018, 1, 2)
     s = schedules.IntervalSchedule(start_date=start_date,
                                    interval=timedelta(days=1),
                                    end_date=end_date)
     assert s.next(3, after=start_date) == [start_date.add(days=1)]
     assert s.next(3, after=pendulum.datetime(2018, 2, 1)) == []
コード例 #7
0
 def test_interval_schedule_doesnt_compute_dates_before_start_date(self):
     start_date = pendulum.datetime(2018, 1, 1)
     s = schedules.IntervalSchedule(start_date=start_date,
                                    interval=timedelta(hours=1))
     assert s.next(3, after=pendulum.datetime(2000, 1, 1)) == [
         start_date,
         start_date.add(hours=1),
         start_date.add(hours=2),
     ]
コード例 #8
0
 def test_interval_schedule_next_n_with_after_argument(self):
     start_date = pendulum.datetime(2018, 1, 1)
     today = pendulum.today("UTC")
     s = schedules.IntervalSchedule(start_date, timedelta(days=1))
     assert s.next(3, after=today) == [
         today.add(days=1),
         today.add(days=2),
         today.add(days=3),
     ]
コード例 #9
0
 def test_interval_schedule_respects_microseconds(self):
     start_date = pendulum.datetime(2018, 1, 1, 0, 0, 0, 1)
     s = schedules.IntervalSchedule(start_date=start_date,
                                    interval=timedelta(hours=1))
     assert s.next(3, after=pendulum.datetime(2010, 1, 1)) == [
         start_date,
         start_date.add(hours=1),
         start_date.add(hours=2),
     ]
コード例 #10
0
 def test_interval_schedule_next_n(self):
     """Test that default after is *now*"""
     start_date = pendulum.datetime(2018, 1, 1)
     today = pendulum.today("UTC")
     s = schedules.IntervalSchedule(start_date, timedelta(days=1))
     assert s.next(3) == [
         today.add(days=1),
         today.add(days=2),
         today.add(days=3)
     ]
コード例 #11
0
 def test_serialize_interval_schedule(self):
     sd = pendulum.datetime(2000, 1, 1)
     schedule = schedules.IntervalSchedule(interval=timedelta(hours=1),
                                           start_date=sd)
     assert schedule.serialize() == {
         "type": "IntervalSchedule",
         "start_date": serialize_fmt(sd),
         "end_date": None,
         "interval": 3600000000,
         "__version__": __version__,
     }
コード例 #12
0
ファイル: test_schedules.py プロジェクト: weblearngit/prefect
def test_deserialize_schedule_with_overridden_interval():
    schedule = schedules.IntervalSchedule(
        start_date=pendulum.now("utc"), interval=datetime.timedelta(minutes=1))
    schedule.interval = datetime.timedelta(microseconds=1)
    schema = schemas.IntervalScheduleSchema()
    serialized = schema.dump(schedule)
    assert serialized["interval"] == 1

    with pytest.raises(ValueError) as exc:
        schema.load(serialized)
    assert "Interval can not be less than one minute." in str(exc.value)
コード例 #13
0
 def test_interval_schedule_respects_after_in_middle_of_interval(self):
     """
     If the "after" date is in the middle of an interval, then the IntervalSchedule
     should advance to the next interval.
     """
     start_date = pendulum.datetime(2018, 1, 1)
     s = schedules.IntervalSchedule(start_date=start_date,
                                    interval=timedelta(hours=1))
     assert s.next(2, after=start_date + timedelta(microseconds=1)) == [
         start_date.add(hours=1),
         start_date.add(hours=2),
     ]
コード例 #14
0
 def test_interval_schedule_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")
     s = schedules.IntervalSchedule(dt, timedelta(hours=1))
     if serialize:
         s = ScheduleSchema().load(s.serialize())
     next_4 = s.next(4, after=dt)
     # repeat the 1am run in local time
     assert [t.in_tz("America/New_York").hour
             for t in next_4] == [0, 1, 1, 2]
     # runs every hour UTC
     assert [t.in_tz("UTC").hour for t in next_4] == [4, 5, 6, 7]
コード例 #15
0
 def test_interval_schedule_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")
     s = schedules.IntervalSchedule(dt, timedelta(hours=1))
     if serialize:
         s = ScheduleSchema().load(s.serialize())
     next_4 = s.next(4, after=dt)
     # 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]
コード例 #16
0
    def list_of_schedules(self):
        sd = pendulum.datetime(2000, 1, 1)
        ed = pendulum.datetime(2010, 1, 1)

        list_sched = []
        list_sched.append(
            schedules.IntervalSchedule(interval=timedelta(hours=1),
                                       start_date=sd,
                                       end_date=ed))

        sd = pendulum.datetime(2004, 1, 1)
        ed = pendulum.datetime(2017, 1, 1)
        list_sched.append(
            schedules.CronSchedule("0 0 * * *", start_date=sd, end_date=ed))
        list_sched.append(schedules.CronSchedule("0 9 * * 1-5"))
        return list_sched
コード例 #17
0
    def test_interval_schedule_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")
        s = schedules.IntervalSchedule(dt, timedelta(days=1))
        if serialize:
            s = ScheduleSchema().load(s.serialize())
        next_4 = s.next(4, after=dt)
        # 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]
コード例 #18
0
ファイル: test_schedules.py プロジェクト: weblearngit/prefect
def interval_schedule():
    return schedules.IntervalSchedule(
        interval=datetime.timedelta(hours=1),
        start_date=datetime.datetime(2020, 1, 1),
        end_date=datetime.datetime(2020, 5, 1),
    )
コード例 #19
0
 def test_next_n_with_repeated_schedule_values(self):
     start_date = pendulum.datetime(2018, 1, 1)
     now = pendulum.now("UTC")
     s = schedules.IntervalSchedule(start_date, timedelta(days=1))
     main = schedules.UnionSchedule([s, s, s, s])
     assert main.next(3) == s.next(3)
コード例 #20
0
 def test_create_interval_schedule(self):
     assert schedules.IntervalSchedule(start_date=pendulum.now("UTC"),
                                       interval=timedelta(days=1))
コード例 #21
0
 def test_start_date_must_be_datetime(self):
     with pytest.raises(TypeError):
         schedules.IntervalSchedule(start_date=None,
                                    interval=timedelta(hours=-1))
コード例 #22
0
 def test_interval_schedule_interval_must_be_positive(self):
     with pytest.raises(ValueError):
         schedules.IntervalSchedule(pendulum.now("UTC"),
                                    interval=timedelta(hours=-1))
コード例 #23
0
ファイル: large_example_flow.py プロジェクト: hishoss/praetor
import prefect
from prefect import schedules
from praetor import Flow, Task, task
import time
from random import randint
from datetime import timedelta

schedule = schedules.IntervalSchedule(interval=timedelta(minutes=1))
flow = Flow("large_example_flow")


def tsk(x=None):
    time.sleep(randint(3, 5))


with flow:
    start = task(tsk, name="start")

    tables = ["BOB5", "BOB6", "GRP", "LYU1", "LYU2", "LYU3-4", "RIK", "ZHU"]

    sync_table = task(tsk, name="sync_table")
    copy_table = task(tsk, name="copy_table")
    t1 = sync_table.map(tables)
    t2 = copy_table.map(t1)
    start.set_downstream(t1)

#     delete_tc = task(tsk, name="delete_tc")
#     copy_tc = task(tsk, name="copy_tc")
#     start.set_downstream(delete_tc)
#     delete_tc.set_downstream(copy_tc)
コード例 #24
0
 def test_interval_schedule_n_is_negative(self):
     start_date = pendulum.datetime(2018, 1, 1)
     s = schedules.IntervalSchedule(start_date=start_date,
                                    interval=timedelta(hours=1))
     assert s.next(-3) == []