Plone/Zope基于时间的事件机制
项目描述
collective.timedevents
概述
collective.timedevents 会触发基于时钟的 Zope 3 事件。它们可以使 Zope 应用程序响应计时器。这对于创建需要定期执行或经过一定时间后发生的服务非常有用。
这是一个面向开发者的产品。该产品旨在用更健壮的 Zope 3 代码库替换 Products.TickingMachine。
有两种不同的使用方式
使用 ITickEvent 并在事件订阅者中计算是否需要执行操作。这将还会通过保持事件计时持续来处理 Zope 重启时的计时。
订阅任何 cron 风格的 IIntervalTicks*-事件,无需担心客户端的计时。对于较长的计时(每周、每月),cron 作业作为触发器最为合适,在 Zope 重启的情况下。
由 Travis 测试
安装
将 collective.timedevents 添加到您的 buildout 中,通过在 buildout.cfg 中添加 egg 来实现
eggs = ... collective.timedevents
触发器
可以是 cron 作业或 Zope 时钟服务器。
将时钟服务器添加到触发定时事件订阅者 - 使用您的 Plone 实例名称
[instance] ... zope-conf-additional = <clock-server> method /mysite/@@tick period 90 user clockserver-user password password host localhost </clock-server>
或者对于类似 cron 的基于间隔的事件,这里 900 秒对应 15 分钟的事件
<clock-server> method /mysite/@@tick_fifteen period 900 user clockserver-user password password host localhost </clock-server>
现在您应该开始在 Zope 事件日志中看到计时器了。
用法
订阅您需要的事件/计时器。
使用 ITickEvent 方法
将 collective.timedevents.interfaces.ITickEvent 订阅者添加到您的产品 ZCML 声明中
<configure xmlns="http://namespaces.zope.org/zope" xmlns:browser="http://namespaces.zope.org/browser" i18n_domain="harvinaiset.app"> <subscriber handler="myproduct.tickers.on_tick" for="collective.timedevents.interfaces.ITickEvent" /> </configure>配置您的事件处理器以在经过一定时间后做出反应
from zope.app.component.hooks import getSite def on_tick(event): """ Do something after one hour has elapsed """ interval_in_days = 1.0 / 24.0 # One hour, floating point context = site.my_magic_context # Persistent object which stores our timing data if event.last_tick > context.last_action + interval_in_days: # Check whether enough time has elaped do_stuff() context.last_action = event.last_tick # Store when we last time did something
使用 IIntervalTicks*-事件
将 collective.timedevents.interfaces.IIntervalTicks* 订阅者添加到您的模块 ZCML 声明中
<configure xmlns="http://namespaces.zope.org/zope" xmlns:browser="http://namespaces.zope.org/browser" i18n_domain="mymodule"> <subscriber handler="myproduct.tickers.on_tick_fifteen" for="collective.timedevents.intefaces.IIntervalTicks15Event" /> </configure>
其他
所有计时代码都在管理员权限下执行。
ITickEvent 的默认计时周期为 300 秒。这可以在 views.py 中进行控制。
ITickEvent 的计时由 configure.zcml 中定义的 events.tick_logger 记录。
质量保证
该产品符合以下质量标准
提供了单元测试
提供了良好的文档
有注释的代码
提供了 PyPi eggs
变更日志
1.1 (2021-08-26)
添加 Python 3 & Plone 5.2 兼容性 [boulch]
使用 github CI 进行自动化测试 [tomgross]
1.0.3 (2016-02-01)
最后尝试将 HISTORY.txt 包含到 egg 中 [tomgross]
1.0.2 (2016-02-01)
修复 brown bag 发布第 2 部分 [tomgross]
1.0.1 (2016-02-01)
修复 brown bag 发布 [tomgross]
1.0 (2016-01-30)
Plone 5 兼容性 [karalics, tomgross]
0.3 (2013-12-14)
Travis CI 集成 [hvelarde]
添加 cron 风格的计时事件,可由 cron 或时钟服务器触发,无需内部计算间隔。更新了 readme 和测试。 [sunew]
0.2.1 (2012-04-24)
为 tick_logger 添加日志级别选项 [vmaksymiv]
修复:数据存储
0.2
添加 Plone 4 兼容性 [kroman0]
0.1.1 (2008-11-04)
PyPi egg 修复
0.1
初始版本
项目详情
collective.timedevents-1.1.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | df5498a76ebfe099576da253d9e2f4b1d33b31ccc488a777d0d7b18fde7afcc2 |
|
MD5 | d2ad8ea7ff1ba62b90a65c529aaea5fc |
|
BLAKE2b-256 | e307df9b0fe0fdefc02b31af70b57f601e72110a423dad07f0731337b245f7bb |