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


Python pendulum.now方法代码示例

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


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

示例1: stream_replicate

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import now [as 别名]
def stream_replicate():
    """Monitor changes in approximately real-time and replicate them"""
    stream = primary.stream(SomeDataBlob, "trim_horizon")
    next_heartbeat = pendulum.now()
    while True:
        now = pendulum.now()
        if now >= next_heartbeat:
            stream.heartbeat()
            next_heartbeat = now.add(minutes=10)

        record = next(stream)
        if record is None:
            continue
        if record["new"] is not None:
            replica.save(record["new"])
        else:
            replica.delete(record["old"]) 
开发者ID:numberoverzero,项目名称:bloop,代码行数:19,代码来源:replication.py

示例2: test_read_with_match_phrase_query

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import now [as 别名]
def test_read_with_match_phrase_query(self):
        similar_log_id = '{task_id}-{dag_id}-2016-01-01T00:00:00+00:00-1'.format(
            dag_id=TestElasticsearchTaskHandler.DAG_ID,
            task_id=TestElasticsearchTaskHandler.TASK_ID)
        another_test_message = 'another message'

        another_body = {'message': another_test_message, 'log_id': similar_log_id, 'offset': 1}
        self.es.index(index=self.index_name, doc_type=self.doc_type,
                      body=another_body, id=1)

        ts = pendulum.now()
        logs, metadatas = self.es_task_handler.read(self.ti,
                                                    1,
                                                    {'offset': 0,
                                                     'last_log_timestamp': str(ts),
                                                     'end_of_log': False})
        self.assertEqual(1, len(logs))
        self.assertEqual(len(logs), len(metadatas))
        self.assertEqual(self.test_message, logs[0])
        self.assertNotEqual(another_test_message, logs[0])

        self.assertFalse(metadatas[0]['end_of_log'])
        self.assertEqual('1', metadatas[0]['offset'])
        self.assertTrue(timezone.parse(metadatas[0]['last_log_timestamp']) > ts) 
开发者ID:apache,项目名称:airflow,代码行数:26,代码来源:test_es_task_handler.py

示例3: test_read_nonexistent_log

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import now [as 别名]
def test_read_nonexistent_log(self):
        ts = pendulum.now()
        # In ElasticMock, search is going to return all documents with matching index
        # and doc_type regardless of match filters, so we delete the log entry instead
        # of making a new TaskInstance to query.
        self.es.delete(index=self.index_name, doc_type=self.doc_type, id=1)
        logs, metadatas = self.es_task_handler.read(self.ti,
                                                    1,
                                                    {'offset': 0,
                                                     'last_log_timestamp': str(ts),
                                                     'end_of_log': False})
        self.assertEqual(1, len(logs))
        self.assertEqual(len(logs), len(metadatas))
        self.assertEqual([''], logs)
        self.assertFalse(metadatas[0]['end_of_log'])
        self.assertEqual('0', metadatas[0]['offset'])
        # last_log_timestamp won't change if no log lines read.
        self.assertTrue(timezone.parse(metadatas[0]['last_log_timestamp']) == ts) 
开发者ID:apache,项目名称:airflow,代码行数:20,代码来源:test_es_task_handler.py

示例4: test_read_with_empty_metadata

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import now [as 别名]
def test_read_with_empty_metadata(self):
        ts = pendulum.now()
        logs, metadatas = self.es_task_handler.read(self.ti, 1, {})
        self.assertEqual(1, len(logs))
        self.assertEqual(len(logs), len(metadatas))
        self.assertEqual(self.test_message, logs[0])
        self.assertFalse(metadatas[0]['end_of_log'])
        # offset should be initialized to 0 if not provided.
        self.assertEqual('1', metadatas[0]['offset'])
        # last_log_timestamp will be initialized using log reading time
        # if not last_log_timestamp is provided.
        self.assertTrue(timezone.parse(metadatas[0]['last_log_timestamp']) > ts)

        # case where offset is missing but metadata not empty.
        self.es.delete(index=self.index_name, doc_type=self.doc_type, id=1)
        logs, metadatas = self.es_task_handler.read(self.ti, 1, {'end_of_log': False})
        self.assertEqual(1, len(logs))
        self.assertEqual(len(logs), len(metadatas))
        self.assertEqual([''], logs)
        self.assertFalse(metadatas[0]['end_of_log'])
        # offset should be initialized to 0 if not provided.
        self.assertEqual('0', metadatas[0]['offset'])
        # last_log_timestamp will be initialized using log reading time
        # if not last_log_timestamp is provided.
        self.assertTrue(timezone.parse(metadatas[0]['last_log_timestamp']) > ts) 
开发者ID:apache,项目名称:airflow,代码行数:27,代码来源:test_es_task_handler.py

示例5: test_sync_to_db_default_view

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import now [as 别名]
def test_sync_to_db_default_view(self, mock_now):
        dag = DAG(
            'dag',
            start_date=DEFAULT_DATE,
            default_view="graph",
        )
        with dag:
            DummyOperator(task_id='task', owner='owner1')
            SubDagOperator(
                task_id='subtask',
                owner='owner2',
                subdag=DAG(
                    'dag.subtask',
                    start_date=DEFAULT_DATE,
                )
            )
        now = datetime.datetime.utcnow().replace(tzinfo=pendulum.timezone('UTC'))
        mock_now.return_value = now
        session = settings.Session()
        dag.sync_to_db(session=session)

        orm_dag = session.query(DagModel).filter(DagModel.dag_id == 'dag').one()
        self.assertIsNotNone(orm_dag.default_view)
        self.assertEqual(orm_dag.default_view, "graph")
        session.close() 
开发者ID:apache,项目名称:airflow,代码行数:27,代码来源:test_dag.py

示例6: test_email_alert

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import now [as 别名]
def test_email_alert(self, mock_send_email):
        dag = models.DAG(dag_id='test_failure_email')
        task = BashOperator(
            task_id='test_email_alert',
            dag=dag,
            bash_command='exit 1',
            start_date=DEFAULT_DATE,
            email='to')

        ti = TI(task=task, execution_date=datetime.datetime.now())

        try:
            ti.run()
        except AirflowException:
            pass

        (email, title, body), _ = mock_send_email.call_args
        self.assertEqual(email, 'to')
        self.assertIn('test_email_alert', title)
        self.assertIn('test_email_alert', body)
        self.assertIn('Try 1', body) 
开发者ID:apache,项目名称:airflow,代码行数:23,代码来源:test_taskinstance.py

示例7: test_success_callback_no_race_condition

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import now [as 别名]
def test_success_callback_no_race_condition(self):
        callback_wrapper = CallbackWrapper()
        dag = DAG('test_success_callback_no_race_condition', start_date=DEFAULT_DATE,
                  end_date=DEFAULT_DATE + datetime.timedelta(days=10))
        task = DummyOperator(task_id='op', email='test@test.test',
                             on_success_callback=callback_wrapper.success_handler, dag=dag)
        ti = TI(task=task, execution_date=datetime.datetime.now())
        ti.state = State.RUNNING
        session = settings.Session()
        session.merge(ti)
        session.commit()
        callback_wrapper.wrap_task_instance(ti)
        ti._run_raw_task()
        self.assertTrue(callback_wrapper.callback_ran)
        self.assertEqual(callback_wrapper.task_state_in_callback, State.RUNNING)
        ti.refresh_from_db()
        self.assertEqual(ti.state, State.SUCCESS) 
开发者ID:apache,项目名称:airflow,代码行数:19,代码来源:test_taskinstance.py

示例8: test_execute_callback

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import now [as 别名]
def test_execute_callback(self):
        called = False

        def on_execute_callable(context):
            nonlocal called
            called = True
            self.assertEqual(
                context['dag_run'].dag_id,
                'test_dagrun_execute_callback'
            )

        dag = DAG('test_execute_callback', start_date=DEFAULT_DATE,
                  end_date=DEFAULT_DATE + datetime.timedelta(days=10))
        task = DummyOperator(task_id='op', email='test@test.test',
                             on_execute_callback=on_execute_callable,
                             dag=dag)
        ti = TI(task=task, execution_date=datetime.datetime.now())
        ti.state = State.RUNNING
        session = settings.Session()
        session.merge(ti)
        session.commit()
        ti._run_raw_task()
        assert called
        ti.refresh_from_db()
        assert ti.state == State.SUCCESS 
开发者ID:apache,项目名称:airflow,代码行数:27,代码来源:test_taskinstance.py

示例9: choose_branch

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import now [as 别名]
def choose_branch(self, context: Dict) -> Union[str, Iterable[str]]:
        # If the DAG Run is externally triggered, then return without
        # skipping downstream tasks
        if context['dag_run'] and context['dag_run'].external_trigger:
            self.log.info(
                "Externally triggered DAG_Run: allowing execution to proceed.")
            return list(context['task'].get_direct_relative_ids(upstream=False))

        now = pendulum.now('UTC')
        left_window = context['dag'].following_schedule(
            context['execution_date'])
        right_window = context['dag'].following_schedule(left_window)
        self.log.info(
            'Checking latest only with left_window: %s right_window: %s now: %s',
            left_window, right_window, now
        )

        if not left_window < now <= right_window:
            self.log.info('Not latest execution, skipping downstream.')
            # we return an empty list, thus the parent BaseBranchOperator
            # won't exclude any downstream tasks from skipping.
            return []
        else:
            self.log.info('Latest, allowing execution to proceed.')
            return list(context['task'].get_direct_relative_ids(upstream=False)) 
开发者ID:apache,项目名称:airflow,代码行数:27,代码来源:latest_only_operator.py

示例10: notify

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import now [as 别名]
def notify(self, service, now):
        msg = '{service.name}({service.value},{service.grace}) not send heartbeat at {now}'.format(
            service=service,
            now=now.in_timezone(settings.TIME_ZONE).to_datetime_string()
        )
        logger.warning(msg)

        if not service.notify_to.strip():
            logger.warning('service %s notify_to is empty', service.name)
            return

        notify_async(service.notify_to.strip().split(";"),
                     service.name,
                     service.tp,
                     service.value,
                     service.grace,
                     msg
                     ) 
开发者ID:510908220,项目名称:heartbeats,代码行数:20,代码来源:check.py

示例11: process_at_service

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import now [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

示例12: api_invite_delete

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import now [as 别名]
def api_invite_delete(self, client_ctx, msg):
        msg = invite_delete_serializer.req_load(msg)
        try:
            await self.delete(
                organization_id=client_ctx.organization_id,
                greeter=client_ctx.user_id,
                token=msg["token"],
                on=pendulum_now(),
                reason=msg["reason"],
            )

        except InvitationNotFoundError:
            return {"status": "not_found"}

        except InvitationAlreadyDeletedError:
            return {"status": "already_deleted"}

        return invite_delete_serializer.rep_dump({"status": "ok"}) 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:20,代码来源:invite.py

示例13: new_for_device

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import now [as 别名]
def new_for_device(
        self,
        organization_id: OrganizationID,
        greeter_user_id: UserID,
        created_on: Optional[Pendulum] = None,
    ) -> DeviceInvitation:
        """
        Raise: Nothing
        """
        created_on = created_on or pendulum_now()
        async with self.dbh.pool.acquire() as conn, conn.transaction():
            token = await _do_new_user_invitation(
                conn,
                organization_id=organization_id,
                greeter_user_id=greeter_user_id,
                claimer_email=None,
                created_on=created_on,
            )
        return DeviceInvitation(
            greeter_user_id=greeter_user_id,
            greeter_human_handle=None,
            token=token,
            created_on=created_on,
        ) 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:26,代码来源:invite.py

示例14: api_vlob_create

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import now [as 别名]
def api_vlob_create(self, client_ctx, msg):
        msg = vlob_create_serializer.req_load(msg)

        now = pendulum.now()
        if not timestamps_in_the_ballpark(msg["timestamp"], now):
            return {"status": "bad_timestamp", "reason": f"Timestamp is out of date."}

        try:
            await self.create(client_ctx.organization_id, client_ctx.device_id, **msg)

        except VlobAlreadyExistsError as exc:
            return vlob_create_serializer.rep_dump({"status": "already_exists", "reason": str(exc)})

        except VlobAccessError:
            return vlob_create_serializer.rep_dump({"status": "not_allowed"})

        except VlobEncryptionRevisionError:
            return vlob_create_serializer.rep_dump({"status": "bad_encryption_revision"})

        except VlobInMaintenanceError:
            return vlob_create_serializer.rep_dump({"status": "in_maintenance"})

        return vlob_create_serializer.rep_dump({"status": "ok"}) 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:25,代码来源:vlob.py

示例15: create_realm

# 需要导入模块: import pendulum [as 别名]
# 或者: from pendulum import now [as 别名]
def create_realm(self, realm_id: EntryID):
        """
        Raises:
            FSError
            FSBackendOfflineError
        """
        certif = RealmRoleCertificateContent.build_realm_root_certif(
            author=self.device.device_id, timestamp=pendulum_now(), realm_id=realm_id
        ).dump_and_sign(self.device.signing_key)

        rep = await self._backend_cmds("realm_create", certif)
        if rep["status"] == "already_exists":
            # It's possible a previous attempt to create this realm
            # succeeded but we didn't receive the confirmation, hence
            # we play idempotent here.
            return
        elif rep["status"] != "ok":
            raise FSError(f"Cannot create realm {realm_id}: `{rep['status']}`") 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:20,代码来源:remote_loader.py


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