Esempio n. 1
0
def test_create_missing_items():
    FlowItem.delete().where(FlowItem.name == FLOW_NAME).execute()

    worktime = pendulum.datetime(2020, 1, 6, tz="Europe/Moscow")
    interval_timedelta = dt.timedelta(1)

    items = FlowItem.create_missing_items(
        flow_name=FLOW_NAME,
        start_time=worktime - dt.timedelta(5),
        end_time=worktime - dt.timedelta(5),
        interval_timedelta=interval_timedelta,
    )

    assert len(items) == 1

    FlowItem.create(**{FlowItem.name.name: FLOW_NAME, FlowItem.worktime.name: worktime})

    FlowItem.create_missing_items(
        flow_name=FLOW_NAME,
        start_time=worktime - dt.timedelta(5),
        end_time=worktime,
        interval_timedelta=interval_timedelta,
    )

    assert (
        FlowItem.select()
        .where(FlowItem.name == FLOW_NAME, FlowItem.status == FlowStatus.add)
        .count()
    ) == 6
Esempio n. 2
0
    def resource_items(self, start_period, end_period,
                       **kwargs) -> Iterator[ExportContext]:
        query: peewee.ModelSelect = FlowItem.select()

        if self.export.export_mode == "by_date":
            query = query.where(FlowItem.worktime >= start_period,
                                FlowItem.worktime <= end_period)

        yield ExportContext(
            columns=self.export.columns,
            data=list(query.dicts()),
            data_orient=DataOrient.dict,
        )
Esempio n. 3
0
def test_retries(create_retries, retries, result):
    # TODO: Не работает с started_utc=None
    FlowItem.delete().where(FlowItem.name == FLOW_NAME).execute()

    FlowItem.create(
        **{
            FlowItem.name.name: FLOW_NAME,
            FlowItem.worktime.name: pendulum.datetime(2020, 1, 1, tz="Europe/Moscow"),
            FlowItem.started_utc.name: dt.datetime(2020, 1, 1),
            FlowItem.status.name: FlowStatus.error,
            FlowItem.retries.name: create_retries,
        }
    )

    FlowItem.retry_error_items(FLOW_NAME, retries=retries, retry_delay=60)

    items = FlowItem.select().where(
        FlowItem.name == FLOW_NAME, FlowItem.status == FlowStatus.add
    )

    assert len(items) == int(result)
Esempio n. 4
0
def test_retry_delay(retry_delay, passed_sec, is_run):
    # TODO: Не работает с started_utc=None
    FlowItem.delete().where(FlowItem.name == FLOW_NAME).execute()

    FlowItem.create(
        **{
            FlowItem.name.name: FLOW_NAME,
            FlowItem.worktime.name: pendulum.datetime(2020, 1, 1, tz="Europe/Moscow"),
            FlowItem.started_utc.name: dt.datetime(2020, 1, 1, 0, 0, 0),
            FlowItem.status.name: FlowStatus.error,
            FlowItem.retries.name: 0,
        }
    )

    FlowItem.get_utcnow = Mock(return_value=dt.datetime(2020, 1, 1, 0, 0, passed_sec))

    FlowItem.retry_error_items(FLOW_NAME, retries=1, retry_delay=retry_delay)

    items = FlowItem.select().where(
        FlowItem.name == FLOW_NAME, FlowItem.status == FlowStatus.add
    )

    assert len(items) == int(is_run)