def test_allow_execute_flow(): FlowItem.delete().where(FlowItem.name == FLOW_NAME).execute() worktime = pendulum.datetime(2020, 1, 6, tz="Europe/Moscow") interval_timedelta = dt.timedelta(1) worktime_list = iter_range_datetime( start_time=worktime - dt.timedelta(3), end_time=worktime, timedelta=interval_timedelta, ) FlowItem.create_items( flow_name=FLOW_NAME, worktime_list=worktime_list, status=Statuses.fatal_error, notebook_hash="", ) assert (FlowItem.allow_execute_flow( FLOW_NAME, notebook_hash="", max_fatal_errors=3) is False) assert (FlowItem.allow_execute_flow( FLOW_NAME, notebook_hash="new", max_fatal_errors=3) is True) FlowItem.recreate_prev_items( flow_name=FLOW_NAME, worktime=worktime, offset_periods=10, interval_timedelta=interval_timedelta, ) assert (FlowItem.allow_execute_flow( FLOW_NAME, notebook_hash="", max_fatal_errors=3) is True)
def test_create_update_error_items(): FlowItem.delete().where(FlowItem.name == FLOW_NAME).execute() worktime = pendulum.datetime(2020, 1, 1, tz="Europe/Moscow") interval_timedelta = dt.timedelta(1) items = FlowItem.recreate_prev_items( flow_name=FLOW_NAME, worktime=worktime, offset_periods=[-1, -2], interval_timedelta=interval_timedelta, ) assert items is None for i in range(10): FlowItem.create( **{ FlowItem.name.name: FLOW_NAME, FlowItem.worktime.name: worktime - dt.timedelta(i), FlowItem.status.name: FlowStatus.error, } ) items = FlowItem.recreate_prev_items( flow_name=FLOW_NAME, worktime=worktime, offset_periods=[-1, -2], interval_timedelta=interval_timedelta, ) assert len(items) == 2 assert FlowItem.count_items(FLOW_NAME, statuses=[FlowStatus.add]) == 2 for i in items: assert i.retries == 0
def test_create_update_items_start_time_equals_worktime(): """Checking when the update date is equals the first worktime.""" FlowItem.delete().where(FlowItem.name == FLOW_NAME).execute() worktime = pendulum.datetime(2020, 1, 1, tz="Europe/Moscow") interval_timedelta = dt.timedelta(1) FlowItem.create( **{ FlowItem.name.name: FLOW_NAME, FlowItem.worktime.name: worktime, FlowItem.status.name: Statuses.error, }) items = FlowItem.recreate_prev_items( flow_name=FLOW_NAME, worktime=worktime, offset_periods=[-1, -2, -3], interval_timedelta=interval_timedelta, ) assert len(items) == 0