当前位置: 首页>>代码示例>>Python>>正文


Python pendulum.instance方法代码示例

本文整理汇总了Python中pendulum.instance方法的典型用法代码示例。如果您正苦于以下问题:Python pendulum.instance方法的具体用法?Python pendulum.instance怎么用?Python pendulum.instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pendulum的用法示例。


在下文中一共展示了pendulum.instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_next_retry_datetime_short_intervals

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import instance [as 别名]
def test_next_retry_datetime_short_intervals(self):
        delay = datetime.timedelta(seconds=1)
        max_delay = datetime.timedelta(minutes=60)

        dag = models.DAG(dag_id='fail_dag')
        task = BashOperator(
            task_id='task_with_exp_backoff_and_short_time_interval',
            bash_command='exit 1',
            retries=3,
            retry_delay=delay,
            retry_exponential_backoff=True,
            max_retry_delay=max_delay,
            dag=dag,
            owner='airflow',
            start_date=timezone.datetime(2016, 2, 1, 0, 0, 0))
        ti = TI(
            task=task, execution_date=DEFAULT_DATE)
        ti.end_date = pendulum.instance(timezone.utcnow())

        date = ti.next_retry_datetime()
        # between 1 * 2^0.5 and 1 * 2^1 (15 and 30)
        period = ti.end_date.add(seconds=15) - ti.end_date.add(seconds=1)
        self.assertTrue(date in period) 
开发者ID:apache,项目名称:airflow,代码行数:25,代码来源:test_taskinstance.py

示例2: are_dependents_done

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import instance [as 别名]
def are_dependents_done(self, session=None):
        """
        Checks whether the immediate dependents of this task instance have succeeded or have been skipped.
        This is meant to be used by wait_for_downstream.

        This is useful when you do not want to start processing the next
        schedule of a task until the dependents are done. For instance,
        if the task DROPs and recreates a table.
        """
        task = self.task

        if not task.downstream_task_ids:
            return True

        ti = session.query(func.count(TaskInstance.task_id)).filter(
            TaskInstance.dag_id == self.dag_id,
            TaskInstance.task_id.in_(task.downstream_task_ids),
            TaskInstance.execution_date == self.execution_date,
            TaskInstance.state.in_([State.SKIPPED, State.SUCCESS]),
        )
        count = ti[0][0]
        return count == len(task.downstream_task_ids) 
开发者ID:apache,项目名称:airflow,代码行数:24,代码来源:taskinstance.py

示例3: filter_for_tis

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import instance [as 别名]
def filter_for_tis(
        tis: Iterable[Union["TaskInstance", TaskInstanceKeyType]]
    ) -> Optional[BooleanClauseList]:
        """Returns SQLAlchemy filter to query selected task instances"""
        TI = TaskInstance
        if not tis:
            return None
        if all(isinstance(t, tuple) for t in tis):
            filter_for_tis = ([and_(TI.dag_id == dag_id,
                                    TI.task_id == task_id,
                                    TI.execution_date == execution_date)
                               for dag_id, task_id, execution_date, _ in tis])
            return or_(*filter_for_tis)
        if all(isinstance(t, TaskInstance) for t in tis):
            filter_for_tis = ([and_(TI.dag_id == ti.dag_id,  # type: ignore
                                    TI.task_id == ti.task_id,  # type: ignore
                                    TI.execution_date == ti.execution_date)  # type: ignore
                               for ti in tis])
            return or_(*filter_for_tis)

        raise TypeError("All elements must have the same type: `TaskInstance` or `TaskInstanceKey`.")


# State of the task instance.
# Stores string version of the task state. 
开发者ID:apache,项目名称:airflow,代码行数:27,代码来源:taskinstance.py

示例4: construct_task_instance

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import instance [as 别名]
def construct_task_instance(self, session=None, lock_for_update=False) -> TaskInstance:
        """
        Construct a TaskInstance from the database based on the primary key

        :param session: DB session.
        :param lock_for_update: if True, indicates that the database should
            lock the TaskInstance (issuing a FOR UPDATE clause) until the
            session is committed.
        :return: the task instance constructed
        """

        qry = session.query(TaskInstance).filter(
            TaskInstance.dag_id == self._dag_id,
            TaskInstance.task_id == self._task_id,
            TaskInstance.execution_date == self._execution_date)

        if lock_for_update:
            ti = qry.with_for_update().first()
        else:
            ti = qry.first()
        return ti 
开发者ID:apache,项目名称:airflow,代码行数:23,代码来源:taskinstance.py

示例5: process_at_service

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import instance [as 别名]
def process_at_service(self, service):
        """
        当 当前时间 > at时,看[at, at + grace]之间是否有上报的数据
        """
        latest_ping = self.get_last_ping(service)
        if not latest_ping:
            return

        at = pendulum.parse(service.value, tz=settings.TIME_ZONE).in_timezone('UTC')
        last_created = pendulum.instance(latest_ping.created)
        now = pendulum.now(tz='UTC')

        if now < at.add(minutes=int(service.grace)):
            return
        if last_created < at:
            self.notify(service, now) 
开发者ID:510908220,项目名称:heartbeats,代码行数:18,代码来源:check.py

示例6: test_hour

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import instance [as 别名]
def test_hour():
    def run(now):
        assert pycron.is_now('* * * * *', now)
        assert pycron.is_now('* 16 * * *', now)
        assert pycron.is_now('* */4 * * *', now)
        assert pycron.is_now('*/7 16 * * *', now)
        assert pycron.is_now('*/7 */8 * * *', now)
        assert pycron.is_now('* 2,8,16 * * *', now)
        assert pycron.is_now('* */9 * * *', now) is False
        assert pycron.is_now('* */5 * * *', now) is False
        assert pycron.is_now('*/3 */4 * * *', now) is False
        assert pycron.is_now('3 16 * * *', now) is False
        assert pycron.is_now('*/8 */3 * * *', now) is False
        assert pycron.is_now('* 2,8 * * *', now) is False
        assert pycron.is_now('* 16-20 * * *', now)
        assert pycron.is_now('* 0-10 * * *', now) is False

    now = datetime(2015, 6, 18, 16, 7)
    run(now)
    run(now.replace(tzinfo=utc))
    run(pendulum.instance(now))
    run(arrow.get(now))
    run(udatetime.from_string(now.isoformat()))
    run(Delorean(datetime=now, timezone='UTC').datetime) 
开发者ID:kipe,项目名称:pycron,代码行数:26,代码来源:test_hour.py

示例7: test_parser

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import instance [as 别名]
def test_parser():
    def run(now):
        assert pycron.is_now('* * * * *', now)
        assert pycron.is_now('* * * 6 *', now)
        assert pycron.is_now('* * * */2 *', now)
        assert pycron.is_now('* * * 1,4,6,12 *', now)
        assert pycron.is_now('* * * 5 *', now) is False
        assert pycron.is_now('* * * */5 *', now) is False
        assert pycron.is_now('* * * 1,4,12 *', now) is False
        assert pycron.MONTH_CHOICES[now.month - 1][1] == 'June'
        assert pycron.is_now('* * * 5-8 *', now)
        assert pycron.is_now('* * * 8-10 *', now) is False

    now = datetime(2015, 6, 18, 16, 7)
    run(now)
    run(now.replace(tzinfo=utc))
    run(pendulum.instance(now))
    run(arrow.get(now))
    run(udatetime.from_string(now.isoformat()))
    run(Delorean(datetime=now, timezone='UTC').datetime) 
开发者ID:kipe,项目名称:pycron,代码行数:22,代码来源:test_month.py

示例8: test_minutes

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import instance [as 别名]
def test_minutes():
    def run(since, now):
        assert pycron.has_been('* * * * *', since, now)
        assert pycron.has_been('0 * * * *', since, now) is False
        assert pycron.has_been('1 * * * *', since, now)
        assert pycron.has_been('2 * * * *', since, now)
        assert pycron.has_been('3 * * * *', since, now)
        assert pycron.has_been('4 * * * *', since, now) is False

    since = datetime(2015, 6, 18, 0, 1)
    now = datetime(2015, 6, 18, 0, 3)
    run(since, now)
    run(since.replace(tzinfo=utc), now.replace(tzinfo=utc))
    run(pendulum.instance(since), pendulum.instance(now))
    run(arrow.get(since), arrow.get(now))
    run(udatetime.from_string(since.isoformat()), udatetime.from_string(now.isoformat()))
    run(Delorean(datetime=since, timezone='UTC').datetime, Delorean(datetime=now, timezone='UTC').datetime) 
开发者ID:kipe,项目名称:pycron,代码行数:19,代码来源:test_has_been.py

示例9: test_hours

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import instance [as 别名]
def test_hours():
    def run(since, now):
        assert pycron.has_been('* * * * *', since, now)
        assert pycron.has_been('* 0 * * *', since, now) is False
        assert pycron.has_been('* 1 * * *', since, now)
        assert pycron.has_been('* 2 * * *', since, now)
        assert pycron.has_been('* 3 * * *', since, now)
        assert pycron.has_been('* 4 * * *', since, now) is False

    since = datetime(2015, 6, 18, 1, 0)
    now = datetime(2015, 6, 18, 3, 0)
    run(since, now)
    run(since.replace(tzinfo=utc), now.replace(tzinfo=utc))
    run(pendulum.instance(since), pendulum.instance(now))
    run(arrow.get(since), arrow.get(now))
    run(udatetime.from_string(since.isoformat()), udatetime.from_string(now.isoformat()))
    run(Delorean(datetime=since, timezone='UTC').datetime, Delorean(datetime=now, timezone='UTC').datetime) 
开发者ID:kipe,项目名称:pycron,代码行数:19,代码来源:test_has_been.py

示例10: test_days

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import instance [as 别名]
def test_days():
    def run(since, now):
        assert pycron.has_been('* * * * *', since, now)
        assert pycron.has_been('* * 0 * *', since, now) is False
        assert pycron.has_been('* * 1 * *', since, now)
        assert pycron.has_been('* * 2 * *', since, now)
        assert pycron.has_been('* * 3 * *', since, now)
        assert pycron.has_been('* * 4 * *', since, now) is False

    since = datetime(2015, 6, 1, 0, 0)
    now = datetime(2015, 6, 3, 0, 0)
    run(since, now)
    run(since.replace(tzinfo=utc), now.replace(tzinfo=utc))
    run(pendulum.instance(since), pendulum.instance(now))
    run(arrow.get(since), arrow.get(now))
    run(udatetime.from_string(since.isoformat()), udatetime.from_string(now.isoformat()))
    run(Delorean(datetime=since, timezone='UTC').datetime, Delorean(datetime=now, timezone='UTC').datetime) 
开发者ID:kipe,项目名称:pycron,代码行数:19,代码来源:test_has_been.py

示例11: test_minute_ranges

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import instance [as 别名]
def test_minute_ranges():
    for i in range(1, 59, 2):
        now = datetime(2015, 6, 18, 0, i)
        assert pycron.is_now('1-59/2 * * * *', now)
        assert pycron.is_now('1-59/2 * * * *', now.replace(tzinfo=utc))
        assert pycron.is_now('1-59/2 * * * *', pendulum.instance(now))
        assert pycron.is_now('1-59/2 * * * *', arrow.get(now))
        assert pycron.is_now('1-59/2 * * * *', udatetime.from_string(now.isoformat()))
        assert pycron.is_now('1-59/2 * * * *', Delorean(datetime=now, timezone='UTC').datetime)

    for i in range(0, 59, 2):
        now = datetime(2015, 6, 18, 0, i)
        assert pycron.is_now('1-59/2 * * * *', now) is False
        assert pycron.is_now('1-59/2 * * * *', now.replace(tzinfo=utc)) is False
        assert pycron.is_now('1-59/2 * * * *', pendulum.instance(now)) is False
        assert pycron.is_now('1-59/2 * * * *', arrow.get(now)) is False
        assert pycron.is_now('1-59/2 * * * *', udatetime.from_string(now.isoformat())) is False
        assert pycron.is_now('1-59/2 * * * *', Delorean(datetime=now, timezone='UTC').datetime) is False 
开发者ID:kipe,项目名称:pycron,代码行数:20,代码来源:test_minute.py

示例12: test_day_matching

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import instance [as 别名]
def test_day_matching():
    def run(now):
        for i in range(0, 7):
            # Test day matching from Sunday onwards...
            now += timedelta(days=1)
            assert pycron.is_now('* * * * %i' % (i), now)
            # Test weekdays
            assert pycron.is_now('* * * * 1,2,3,4,5', now) is (True if i not in [0, 6] else False)
            assert pycron.is_now('* * * * 1-5', now) is (True if i not in [0, 6] else False)
            assert pycron.is_now('* * * * 1,2,3,4-5', now) is (True if i not in [0, 6] else False)
            # Test weekends
            assert pycron.is_now('* * * * 0,6', now) is (True if i in [0, 6] else False)

    now = datetime(2015, 6, 20, 16, 7)
    run(now)
    run(now.replace(tzinfo=utc))
    run(pendulum.instance(now))
    run(arrow.get(now))
    run(udatetime.from_string(now.isoformat()))
    run(Delorean(datetime=now, timezone='UTC').datetime) 
开发者ID:kipe,项目名称:pycron,代码行数:22,代码来源:test_dow.py

示例13: test_dom

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import instance [as 别名]
def test_dom():
    def run(now):
        assert pycron.is_now('* * * * *', now)
        assert pycron.is_now('* * 18 * *', now)
        assert pycron.is_now('* * */6 * *', now)
        assert pycron.is_now('* * 1,16,18 * *', now)
        assert pycron.is_now('* * 19 * *', now) is False
        assert pycron.is_now('* * */4 * *', now) is False
        assert pycron.is_now('* * 1,16 * *', now) is False
        assert pycron.is_now('* * 1,16 * *', now) is False
        assert pycron.is_now('* * 1-20 * *', now)
        assert pycron.is_now('* * 20-31 * *', now) is False

    now = datetime(2015, 6, 18, 16, 7)
    run(now)
    run(now.replace(tzinfo=utc))
    run(pendulum.instance(now))
    run(arrow.get(now))
    run(udatetime.from_string(now.isoformat()))
    run(Delorean(datetime=now, timezone='UTC').datetime) 
开发者ID:kipe,项目名称:pycron,代码行数:22,代码来源:test_dom.py

示例14: on

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import instance [as 别名]
def on(self, year, month, day):
        """
        Returns a new instance with the current date set to a different date.

        :param year: The year
        :type year: int

        :param month: The month
        :type month: int

        :param day: The day
        :type day: int

        :rtype: DateTime
        """
        return self.set(year=int(year), month=int(month), day=int(day)) 
开发者ID:sdispater,项目名称:pendulum,代码行数:18,代码来源:datetime.py

示例15: at

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import instance [as 别名]
def at(self, hour, minute=0, second=0, microsecond=0):
        """
        Returns a new instance with the current time to a different time.

        :param hour: The hour
        :type hour: int

        :param minute: The minute
        :type minute: int

        :param second: The second
        :type second: int

        :param microsecond: The microsecond
        :type microsecond: int

        :rtype: DateTime
        """
        return self.set(
            hour=hour, minute=minute, second=second, microsecond=microsecond
        ) 
开发者ID:sdispater,项目名称:pendulum,代码行数:23,代码来源:datetime.py


注:本文中的pendulum.instance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。