collective.timedevents 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ from importlib.metadata import version
2
+
3
+ __version__ = version("collective.timedevents")
@@ -0,0 +1,63 @@
1
+ <configure
2
+ xmlns="http://namespaces.zope.org/zope"
3
+ xmlns:browser="http://namespaces.zope.org/browser"
4
+ >
5
+
6
+ <include
7
+ package="Products.CMFCore"
8
+ file="permissions.zcml"
9
+ />
10
+
11
+ <browser:page
12
+ name="tick"
13
+ for="*"
14
+ class=".views.TickTriggerView"
15
+ permission="cmf.ManagePortal"
16
+ />
17
+
18
+ <browser:page
19
+ name="tick_fifteen"
20
+ for="*"
21
+ class=".views.IntervalTicksView"
22
+ attribute="fifteenMinutes"
23
+ permission="cmf.ManagePortal"
24
+ />
25
+
26
+ <browser:page
27
+ name="tick_hourly"
28
+ for="*"
29
+ class=".views.IntervalTicksView"
30
+ attribute="hourly"
31
+ permission="cmf.ManagePortal"
32
+ />
33
+
34
+ <browser:page
35
+ name="tick_daily"
36
+ for="*"
37
+ class=".views.IntervalTicksView"
38
+ attribute="daily"
39
+ permission="cmf.ManagePortal"
40
+ />
41
+
42
+ <browser:page
43
+ name="tick_weekly"
44
+ for="*"
45
+ class=".views.IntervalTicksView"
46
+ attribute="weekly"
47
+ permission="cmf.ManagePortal"
48
+ />
49
+
50
+ <browser:page
51
+ name="tick_monthly"
52
+ for="*"
53
+ class=".views.IntervalTicksView"
54
+ attribute="monthly"
55
+ permission="cmf.ManagePortal"
56
+ />
57
+
58
+ <subscriber
59
+ for=".interfaces.ITickEvent"
60
+ handler="collective.timedevents.events.tick_logger"
61
+ />
62
+
63
+ </configure>
@@ -0,0 +1,105 @@
1
+ """
2
+ Time based events
3
+
4
+ http://www.twinapex.com
5
+
6
+ """
7
+
8
+ __author__ = "Mikko Ohtamaa <mikko.ohtamaa@twinapex.com>"
9
+ __copyright__ = "Copyright 2008 Twinapex Research"
10
+ __license__ = "GPL"
11
+ __docformat__ = "epytext"
12
+
13
+
14
+ from collective.timedevents.interfaces import IIntervalTicks15Event
15
+ from collective.timedevents.interfaces import IIntervalTicksDailyEvent
16
+ from collective.timedevents.interfaces import IIntervalTicksGenericEvent
17
+ from collective.timedevents.interfaces import IIntervalTicksHourlyEvent
18
+ from collective.timedevents.interfaces import IIntervalTicksMonthlyEvent
19
+ from collective.timedevents.interfaces import IIntervalTicksWeeklyEvent
20
+ from collective.timedevents.interfaces import ITickEvent
21
+ from DateTime import DateTime
22
+ from zope.component import adapter
23
+ from zope.interface import implementer
24
+
25
+ import logging
26
+ import os
27
+
28
+ LOGGING_LEVEL = {
29
+ "DEBUG": logging.DEBUG,
30
+ "INFO": logging.INFO,
31
+ "WARNING": logging.WARNING,
32
+ "WARN": logging.WARN,
33
+ "ERROR": logging.ERROR,
34
+ "CRITICAL": logging.CRITICAL,
35
+ "FATAL": logging.FATAL,
36
+ }.get(os.environ.get("TICK_LOGGER_LEVEL", "INFO").upper())
37
+
38
+
39
+ @implementer(ITickEvent)
40
+ class TickEvent:
41
+ """This class implements the ITickEvent interface."""
42
+
43
+ def __init__(self, date_time, next_tick):
44
+ self.date_time = DateTime(date_time)
45
+ self.next_tick = DateTime(next_tick)
46
+
47
+
48
+ @adapter(ITickEvent)
49
+ def tick_logger(tick_event):
50
+ """This function is a handler for the ITickEvent. Its purpose is to log all
51
+ ticks.
52
+ """
53
+
54
+ logger = logging.getLogger("collective.timedevents")
55
+ logger.log(LOGGING_LEVEL, "(%s) TICK detected." % tick_event.date_time.ISO())
56
+
57
+
58
+ @implementer(IIntervalTicksGenericEvent)
59
+ class IntervalTicksGenericEvent:
60
+ """
61
+ IntervalTicks generic event
62
+ """
63
+
64
+ def __init__(self, context):
65
+ self.context = context
66
+
67
+
68
+ @implementer(IIntervalTicks15Event)
69
+ class IntervalTicks15Event(IntervalTicksGenericEvent):
70
+ """
71
+ An Event that will be fired every 15 minutes from a cronjob
72
+
73
+ """
74
+
75
+
76
+ @implementer(IIntervalTicksHourlyEvent)
77
+ class IntervalTicksHourlyEvent(IntervalTicksGenericEvent):
78
+ """
79
+ An Event that will be fired hourly from a cronjob
80
+
81
+ """
82
+
83
+
84
+ @implementer(IIntervalTicksDailyEvent)
85
+ class IntervalTicksDailyEvent(IntervalTicksGenericEvent):
86
+ """
87
+ An Event that will be fired daily from a cronjob
88
+
89
+ """
90
+
91
+
92
+ @implementer(IIntervalTicksWeeklyEvent)
93
+ class IntervalTicksWeeklyEvent(IntervalTicksGenericEvent):
94
+ """
95
+ An Event that will be fired weekly from a cronjob
96
+
97
+ """
98
+
99
+
100
+ @implementer(IIntervalTicksMonthlyEvent)
101
+ class IntervalTicksMonthlyEvent(IntervalTicksGenericEvent):
102
+ """
103
+ An Event that will be fired monthly from a cronjob
104
+
105
+ """
@@ -0,0 +1,94 @@
1
+ """
2
+ Time based events
3
+
4
+ """
5
+
6
+ __author__ = "Mikko Ohtamaa <mikko.ohtamaa@twinapex.com>"
7
+ __copyright__ = "Copyright 2008 Twinapex Research"
8
+ __license__ = "GPL"
9
+ __docformat__ = "epytext"
10
+
11
+
12
+ from zope.interface import Attribute
13
+ from zope.interface import Interface
14
+
15
+
16
+ class ITickEvent(Interface):
17
+ """An event signaling a tick (vide the TickingMachine class)."""
18
+
19
+ date_time = Attribute("Time of the last tick")
20
+ next_tick = Attribute("Estimated time of the next tick")
21
+
22
+
23
+ class IIntervalTicksGenericEvent(Interface):
24
+ """
25
+ Generic cron event
26
+ """
27
+
28
+ context = Attribute("An acquisition context to be passed to the cron handler")
29
+
30
+
31
+ class IIntervalTicks15Event(IIntervalTicksGenericEvent):
32
+ """
33
+ An Event that will be fired every 15 minutes from a cronjob
34
+
35
+ """
36
+
37
+
38
+ class IIntervalTicksHourlyEvent(IIntervalTicksGenericEvent):
39
+ """
40
+ An Event that will be fired hourly from a cronjob
41
+
42
+ """
43
+
44
+
45
+ class IIntervalTicksDailyEvent(IIntervalTicksGenericEvent):
46
+ """
47
+ An Event that will be fired daily from a cronjob
48
+
49
+ """
50
+
51
+
52
+ class IIntervalTicksWeeklyEvent(IIntervalTicksGenericEvent):
53
+ """
54
+ An Event that will be fired weekly from a cronjob
55
+
56
+ """
57
+
58
+
59
+ class IIntervalTicksMonthlyEvent(IIntervalTicksGenericEvent):
60
+ """
61
+ An Event that will be fired monthly from a cronjob
62
+
63
+ """
64
+
65
+
66
+ class IIntervalTicks(Interface):
67
+ """
68
+ Interface for the cron-style interval notification
69
+ """
70
+
71
+ def fifteenMinutes():
72
+ """
73
+ Notify subscribers about the event fifteenMinutes
74
+ """
75
+
76
+ def hourly():
77
+ """
78
+ Notify subscribers about the event hourly
79
+ """
80
+
81
+ def daily():
82
+ """
83
+ Notify subscribers about the event daily
84
+ """
85
+
86
+ def weekly():
87
+ """
88
+ Notify subscribers about the event weekly
89
+ """
90
+
91
+ def monthly():
92
+ """
93
+ Notify subscribers about the event monthly
94
+ """
@@ -0,0 +1,167 @@
1
+ """
2
+ Unit testing for collective.timedevents
3
+
4
+ http://www.twinapex.com
5
+
6
+ """
7
+
8
+ __author__ = "Mikko Ohtamaa <mikko.ohtamaa@twinapex.com>"
9
+ __copyright__ = "Copyright 2008 Twinapex Research"
10
+ __license__ = "GPL"
11
+ __docformat__ = "epytext"
12
+
13
+ from AccessControl import Unauthorized
14
+ from AccessControl.ImplPython import ZopeSecurityPolicy
15
+ from AccessControl.SecurityManager import setSecurityPolicy
16
+ from collective.timedevents.interfaces import IIntervalTicks15Event
17
+ from collective.timedevents.interfaces import IIntervalTicksDailyEvent
18
+ from collective.timedevents.interfaces import IIntervalTicksHourlyEvent
19
+ from collective.timedevents.interfaces import IIntervalTicksMonthlyEvent
20
+ from collective.timedevents.interfaces import IIntervalTicksWeeklyEvent
21
+ from collective.timedevents.interfaces import ITickEvent
22
+ from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE
23
+ from plone.app.testing import FunctionalTesting
24
+ from plone.app.testing import PloneSandboxLayer
25
+ from plone.app.testing import setRoles
26
+ from plone.app.testing import TEST_USER_ID
27
+ from unittest import TestCase
28
+ from zope import component
29
+
30
+
31
+ class Fixture(PloneSandboxLayer):
32
+
33
+ defaultBases = (PLONE_APP_CONTENTTYPES_FIXTURE,)
34
+
35
+ def setUpZope(self, app, configurationContext):
36
+ import collective.timedevents
37
+
38
+ self.loadZCML(package=collective.timedevents)
39
+
40
+ def setUpPloneSite(self, portal):
41
+ setRoles(portal, TEST_USER_ID, ["Manager"])
42
+
43
+
44
+ FIXTURE = Fixture()
45
+ FUNCTIONAL_TESTING = FunctionalTesting(
46
+ bases=(FIXTURE,), name="collective.timedevents:Functional"
47
+ )
48
+
49
+
50
+ INTERVALVIEWS = [
51
+ ("@@tick_fifteen", IIntervalTicks15Event),
52
+ ("@@tick_hourly", IIntervalTicksHourlyEvent),
53
+ ("@@tick_daily", IIntervalTicksDailyEvent),
54
+ ("@@tick_weekly", IIntervalTicksWeeklyEvent),
55
+ ("@@tick_monthly", IIntervalTicksMonthlyEvent),
56
+ ]
57
+
58
+
59
+ class TickTestCase(TestCase):
60
+ """Test ticking services
61
+
62
+ TODO: Add test for next/last tick code.
63
+ """
64
+
65
+ layer = FUNCTIONAL_TESTING
66
+
67
+ def setUp(self):
68
+ # Set verbose security policy, making debugging Unauthorized
69
+ # exceptions great deal easier in unit tests
70
+ setSecurityPolicy(ZopeSecurityPolicy(verbose=True))
71
+ self.portal = self.layer["portal"]
72
+
73
+ def test_url(self):
74
+ """Test that the tick view URL is exposed properly."""
75
+ setRoles(self.portal, TEST_USER_ID, ["Manager"])
76
+ portal = self.portal
77
+
78
+ view = portal.restrictedTraverse("@@tick")
79
+ view()
80
+
81
+ def test_urls(self):
82
+ """Test that the tick view URL is exposed properly."""
83
+ setRoles(self.portal, TEST_USER_ID, ["Manager"])
84
+
85
+ for v in INTERVALVIEWS:
86
+ view = self.portal.restrictedTraverse(v[0])
87
+ view()
88
+
89
+ def test_security(self):
90
+ """Check that only admin can execute tick."""
91
+ setRoles(self.portal, TEST_USER_ID, [])
92
+ try:
93
+ self.portal.restrictedTraverse("@@tick")
94
+ raise AssertionError("Anonymous could tick")
95
+ except Unauthorized:
96
+ pass
97
+
98
+ def test_security_intervals(self):
99
+ """Check that only admin can execute tick interval views."""
100
+ setRoles(self.portal, TEST_USER_ID, [])
101
+ for v in INTERVALVIEWS:
102
+ try:
103
+ self.portal.restrictedTraverse(v[0])
104
+ raise AssertionError("Anonymous could tick: " + v[0])
105
+ except Unauthorized:
106
+ pass
107
+
108
+ def test_subscription(self):
109
+ """Test that the event subscriber receives a tick."""
110
+
111
+ # global ugly variables work fow now
112
+ global success
113
+ success = False
114
+
115
+ def my_tick(event):
116
+ global success
117
+ success = True
118
+
119
+ component.getSiteManager().registerHandler(my_tick, [ITickEvent])
120
+
121
+ # First
122
+ setRoles(self.portal, TEST_USER_ID, ["Manager"])
123
+ view = self.portal.restrictedTraverse("@@tick")
124
+ view()
125
+
126
+ self.assertEqual(success, True)
127
+
128
+ # Subsequent ticks should have no effect until interval has passed
129
+ success = False
130
+ view()
131
+ self.assertEqual(success, False)
132
+
133
+ # Must unregister, otherwise piclking errors - ZODB tries to store this entry?
134
+ component.getSiteManager().unregisterHandler(my_tick, [ITickEvent])
135
+
136
+ def test_subscriptions(self):
137
+ for v in INTERVALVIEWS:
138
+ self.helper_test_sub(v)
139
+
140
+ def helper_test_sub(self, v):
141
+ """Test that the event subscriber receives a tick."""
142
+
143
+ # global ugly variables work fow now
144
+ global success
145
+ success = False
146
+
147
+ def my_tick(event):
148
+ global success
149
+ success = True
150
+
151
+ component.getSiteManager().registerHandler(my_tick, [v[1]])
152
+
153
+ # First
154
+ setRoles(self.portal, TEST_USER_ID, ["Manager"])
155
+ view = self.portal.restrictedTraverse(v[0])
156
+ view()
157
+
158
+ self.assertEqual(success, True)
159
+
160
+ # All ticks have effect. Interval is handled by the external
161
+ # trigger (cron or clockserver)
162
+ success = False
163
+ view()
164
+ self.assertEqual(success, True)
165
+
166
+ # Must unregister, otherwise piclking errors - ZODB tries to store this entry?
167
+ component.getSiteManager().unregisterHandler(my_tick, [v[1]])
@@ -0,0 +1,201 @@
1
+ """
2
+ Exposed URLs for sending time based events.
3
+
4
+ """
5
+
6
+ __author__ = "Mikko Ohtamaa <mikko.ohtamaa@twinapex.com>"
7
+ __copyright__ = "Copyright 2008 Twinapex Research"
8
+ __license__ = "GPL"
9
+ __docformat__ = "epytext"
10
+
11
+
12
+ from collective.timedevents.events import IntervalTicks15Event
13
+ from collective.timedevents.events import IntervalTicksDailyEvent
14
+ from collective.timedevents.events import IntervalTicksHourlyEvent
15
+ from collective.timedevents.events import IntervalTicksMonthlyEvent
16
+ from collective.timedevents.events import IntervalTicksWeeklyEvent
17
+ from collective.timedevents.events import LOGGING_LEVEL
18
+ from collective.timedevents.events import TickEvent
19
+ from collective.timedevents.interfaces import IIntervalTicks
20
+ from DateTime.DateTime import DateTime
21
+ from plone.protect.interfaces import IDisableCSRFProtection
22
+ from Products.Five.browser import BrowserView
23
+ from zope.event import notify
24
+ from zope.interface import alsoProvides
25
+ from zope.interface import implementer
26
+ from zope.session.session import PersistentSessionDataContainer
27
+ from zope.session.session import SessionData
28
+
29
+ import logging
30
+ import time
31
+
32
+ client_id = "collective.timedevents"
33
+ package_id = "collective.timedevents"
34
+
35
+ logger = logging.getLogger("collective.timedevents")
36
+
37
+
38
+ class TickData:
39
+ """Persistent information about ticking."""
40
+
41
+ def __init__(self, interval):
42
+ self.interval = interval
43
+ self.last_tick = None
44
+
45
+
46
+ # We fake a persistent session using constant client id
47
+ sdc = PersistentSessionDataContainer()
48
+
49
+
50
+ class TickTriggerView(BrowserView):
51
+ """View that is called by Zope clock server.
52
+
53
+ Clock server pulse calls this view regularly. View check whether we have
54
+ enough interval since the last event burst and calls event handlers.
55
+
56
+ Ticking data is kept in Zope persistent session storage,
57
+ using view url as the key.
58
+ """
59
+
60
+ # Interval between send tick events in seconds
61
+ interval = 10
62
+
63
+ def getTickData(self):
64
+ """Lazily initialize run-time tick data.
65
+
66
+ We need to store process shared data somewhere.
67
+ """
68
+
69
+ # Make sure persistent data is not cleared between clock pulses
70
+ sdc.timeout = self.interval * 3
71
+ client_id = "tick-data:" + self.context.absolute_url()
72
+
73
+ try:
74
+ container = sdc[client_id]
75
+ except KeyError:
76
+ container = sdc[client_id] = SessionData()
77
+
78
+ if "interval" not in container:
79
+ # Initialize data
80
+ container["interval"] = self.interval
81
+ container["last_tick"] = None
82
+
83
+ return container
84
+
85
+ def getInterval(self):
86
+ return self.getTickData()["interval"]
87
+
88
+ def setLastTick(self, time):
89
+ self.getTickData()["last_tick"] = time
90
+
91
+ def getLastTick(self):
92
+ return self.getTickData()["last_tick"]
93
+
94
+ def tick(self):
95
+ """Perform tick event firing when needed."""
96
+ # Check current time.
97
+ current = DateTime()
98
+
99
+ # Get lastTick. If it is invalid, set it to the minimum possible value.
100
+ last = self.getLastTick()
101
+
102
+ if not isinstance(last, DateTime):
103
+ last = DateTime(0)
104
+ else:
105
+ pass
106
+
107
+ # Get interval. Make sure the value used here is no lesser than 0.
108
+ interval = self.getInterval()
109
+ if interval < 0:
110
+ interval = 0
111
+
112
+ # If current time less lastTick is equal to or greater than
113
+ # (0.9 * interval) then set lastTick to the current time and
114
+ # execute _notify(). Otherwise do nothing.
115
+ if current.timeTime() - last.timeTime() >= 0.9 * interval:
116
+ self.setLastTick(current)
117
+ notify(
118
+ TickEvent(
119
+ current,
120
+ self.getNextTickEstimation(last_tick=current, interval=interval),
121
+ )
122
+ )
123
+
124
+ def getNextTickEstimation(self, last_tick=None, interval=None):
125
+ """This method tries to estimate a time when a next tick will occur.
126
+ Then it returns a DateTime object representing that time.
127
+ """
128
+ if last_tick is None:
129
+ last_tick = DateTime(self.getLastTick())
130
+
131
+ if interval is None:
132
+ interval = float(self.getInterval())
133
+
134
+ # unit conversion - seconds to days (needed by DateTime)
135
+ interval = interval / 86400.0
136
+
137
+ # compute a DateTime object for the estimated time
138
+ next_tick_estimation = last_tick + interval
139
+
140
+ return next_tick_estimation
141
+
142
+ def __call__(self):
143
+ self.tick()
144
+ return "OK"
145
+
146
+
147
+ @implementer(IIntervalTicks)
148
+ class IntervalTicksView(BrowserView):
149
+ """Cron-style interval based ticking. A zope clockserver or
150
+ cron-job triggers each of methods below. The timing is handled
151
+ by clockserver or cron, not here.
152
+
153
+ For instance, to trigger the hourly event, create a cron-job or
154
+ clockserver setting that goes of every hour, and calls the corresponding
155
+ view by url.
156
+ """
157
+
158
+ def fifteenMinutes(self):
159
+ """
160
+ cron job every 15 minutes
161
+ """
162
+ logger.log(LOGGING_LEVEL, "Firing IntervalTicks15Event")
163
+ notify(IntervalTicks15Event(context=self.context))
164
+ alsoProvides(self.request, IDisableCSRFProtection)
165
+ return "done: %s" % time.strftime("%Y%m%d-%H:%M", time.localtime())
166
+
167
+ def hourly(self):
168
+ """
169
+ Hourly cron job
170
+ """
171
+ logger.log(LOGGING_LEVEL, "Firing IntervalTicksHourlyEvent")
172
+ notify(IntervalTicksHourlyEvent(context=self.context))
173
+ alsoProvides(self.request, IDisableCSRFProtection)
174
+ return "done: %s" % time.strftime("%Y%m%d-%H:%M", time.localtime())
175
+
176
+ def daily(self):
177
+ """
178
+ Daily cron job
179
+ """
180
+ logger.log(LOGGING_LEVEL, "Firing IntervalTicksDailyEvent")
181
+ notify(IntervalTicksDailyEvent(context=self.context))
182
+ alsoProvides(self.request, IDisableCSRFProtection)
183
+ return "done: %s" % time.strftime("%Y%m%d-%H:%M", time.localtime())
184
+
185
+ def weekly(self):
186
+ """
187
+ weekly cron job
188
+ """
189
+ logger.log(LOGGING_LEVEL, "Firing IntervalTicksWeeklyEvent")
190
+ notify(IntervalTicksWeeklyEvent(context=self.context))
191
+ alsoProvides(self.request, IDisableCSRFProtection)
192
+ return "done: %s" % time.strftime("%Y%m%d-%H:%M", time.localtime())
193
+
194
+ def monthly(self):
195
+ """
196
+ monthly cron job
197
+ """
198
+ logger.log(LOGGING_LEVEL, "Firing IntervalTicksMonthlyEvent")
199
+ notify(IntervalTicksMonthlyEvent(context=self.context))
200
+ alsoProvides(self.request, IDisableCSRFProtection)
201
+ return "done: %s" % time.strftime("%Y%m%d-%H:%M", time.localtime())
@@ -0,0 +1,326 @@
1
+ Metadata-Version: 2.4
2
+ Name: collective.timedevents
3
+ Version: 2.0.0
4
+ Summary: Plone/Zope time based event mechanism
5
+ Author-email: Mikko Ohtamaa <mikko.ohtamaa@twinapex.com>
6
+ License-Expression: GPL-2.0-only
7
+ Project-URL: PyPI, https://pypi.org/project/collective.timedevents
8
+ Project-URL: Source, https://github.com/collective/collective.timedevents
9
+ Project-URL: Issues, https://github.com/collective/collective.timedevents/issues
10
+ Project-URL: Changelog, https://github.com/collective/collective.timedevents/blob/master/CHANGES.rst
11
+ Keywords: plone,zope,event,clock,time,subscriber,date,day
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Environment :: Web Environment
14
+ Classifier: Framework :: Plone
15
+ Classifier: Framework :: Plone :: 6.1
16
+ Classifier: Framework :: Plone :: 6.2
17
+ Classifier: Framework :: Plone :: Addon
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python
20
+ Classifier: Programming Language :: Python :: 3
21
+ Classifier: Programming Language :: Python :: 3 :: Only
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Programming Language :: Python :: 3.13
26
+ Classifier: Programming Language :: Python :: 3.14
27
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
28
+ Requires-Python: >=3.10
29
+ Description-Content-Type: text/x-rst
30
+ Requires-Dist: DateTime
31
+ Requires-Dist: plone.protect
32
+ Requires-Dist: Products.CMFCore
33
+ Requires-Dist: Zope
34
+ Requires-Dist: zope.component
35
+ Requires-Dist: zope.event
36
+ Requires-Dist: zope.interface
37
+ Requires-Dist: zope.session
38
+ Provides-Extra: test
39
+ Requires-Dist: plone.app.contenttypes[test]; extra == "test"
40
+ Requires-Dist: plone.app.testing; extra == "test"
41
+ Requires-Dist: plone.classicui; extra == "test"
42
+ Requires-Dist: zest-releaser[recommended]; extra == "test"
43
+ Requires-Dist: zestreleaser-towncrier; extra == "test"
44
+
45
+ collective.timedevents
46
+ ======================
47
+
48
+ Overview
49
+ --------
50
+
51
+ collective.timedevents fires clock based Zope 3 events. They can make
52
+ Zope application react to timers. This is useful for creating services
53
+ where something must happen regularly or after a certain period has
54
+ expired.
55
+
56
+ This is a developer level product. This product is intended to replace
57
+ Products.TickingMachine with more robust Zope 3 codebase.
58
+
59
+ There are two different styles of using it:
60
+
61
+ a) Using the ITickEvent and calculating if action needs to be done in
62
+ the event subscriber. This will also take care of timing over zope
63
+ restarts by keeping event timing persistent.
64
+
65
+ b) Subscribing to any of the cron-style IIntervalTicks\*-events, not
66
+ worrying about the timing client side. For the longer ticks (weekly,
67
+ monthly) a cron-job as trigger makes most sense, in case of zope
68
+ restarts.
69
+
70
+ .. image:: https://github.com/collective/collective.timedevents/actions/workflows/test-matrix.yml/badge.svg
71
+ :target: https://github.com/collective/collective.timedevents/actions/workflows/test-matrix.yml
72
+
73
+ .. contents:: Table of contents
74
+
75
+ Installation
76
+ ------------
77
+
78
+ 1. Add collective.timedevents to your buildout by adding the egg to your
79
+ buildout.cfg::
80
+
81
+ eggs =
82
+ ...
83
+ collective.timedevents
84
+
85
+ 2. Trigger
86
+
87
+ Can either be cron-jobs or zope clock-server.
88
+
89
+ Add clock server to tick timedevents subscribers - use your Plone
90
+ instance name::
91
+
92
+ [instance]
93
+ ...
94
+ zope-conf-additional =
95
+ <clock-server>
96
+ method /mysite/@@tick
97
+ period 90
98
+ user clockserver-user
99
+ password password
100
+ host localhost
101
+ </clock-server>
102
+
103
+ Or for the cron-like interval-based events, here 900 seconds for the
104
+ 15-minute event::
105
+
106
+ <clock-server>
107
+ method /mysite/@@tick_fifteen
108
+ period 900
109
+ user clockserver-user
110
+ password password
111
+ host localhost
112
+ </clock-server>
113
+
114
+ Now you should start to see ticks in the zope event log.
115
+
116
+ Usage
117
+ -----
118
+
119
+ Subscribe to the events/ticks you need.
120
+
121
+ A. Using the ITickEvent method:
122
+
123
+ 1. Add collective.timedevents.interfaces.ITickEvent subscribers to your
124
+ product ZCML declarations::
125
+
126
+ <configure
127
+ xmlns="http://namespaces.zope.org/zope"
128
+ xmlns:browser="http://namespaces.zope.org/browser"
129
+ i18n_domain="harvinaiset.app">
130
+
131
+ <subscriber
132
+ handler="myproduct.tickers.on_tick"
133
+ for="collective.timedevents.interfaces.ITickEvent"
134
+ />
135
+
136
+ </configure>
137
+
138
+ 2. Configure your event handler to react after certain period has
139
+ expired::
140
+
141
+ from zope.app.component.hooks import getSite
142
+
143
+ def on_tick(event):
144
+ """ Do something after one hour has elapsed """
145
+ interval_in_days = 1.0 / 24.0 # One hour, floating point
146
+ context = site.my_magic_context # Persistent object which stores our timing data
147
+ if event.last_tick > context.last_action + interval_in_days: # Check whether enough time has elaped
148
+ do_stuff()
149
+ context.last_action = event.last_tick # Store when we last time did something
150
+
151
+ B. Using the IIntervalTicks\*-events:
152
+
153
+ Add collective.timedevents.interfaces.IIntervalTicks\* subscribers to
154
+ your module ZCML declarations::
155
+
156
+ <configure
157
+ xmlns="http://namespaces.zope.org/zope"
158
+ xmlns:browser="http://namespaces.zope.org/browser"
159
+ i18n_domain="mymodule">
160
+
161
+ <subscriber
162
+ handler="myproduct.tickers.on_tick_fifteen"
163
+ for="collective.timedevents.interfaces.IIntervalTicks15Event"
164
+ />
165
+
166
+ </configure>
167
+
168
+ Other
169
+ -----
170
+
171
+ All ticking code is executed under admin privileges.
172
+
173
+ ITickEvent tick period is 300 seconds by default. This can be controlled
174
+ in views.py.
175
+
176
+ Ticks for ITickEvent are logged by events.tick\_logger defined in
177
+ configure.zcml.
178
+
179
+ Development
180
+ -----------
181
+
182
+ Plone 6.1 on Python 3.10 to 3.13, and Plone 6.2 on Python 3.10 to 3.14. The
183
+ development environment uses `uv <https://docs.astral.sh/uv/>`_::
184
+
185
+ make install # Plone 6.2.3 in .venv (PLONE_VERSION=... to override)
186
+ make create-site # Create a Plone site
187
+ make start # Start Plone on localhost:8080
188
+ make test # Run the tests on Plone 6.2.3 (tox)
189
+ make test-all # Lint and the whole Plone / Python test matrix
190
+ make lint # pre-commit hooks
191
+
192
+ The QA configuration (tox, GitHub Actions, pre-commit) is generated by
193
+ `plone.meta <https://github.com/plone/meta>`_: change ``.meta.toml``, then run
194
+ ``uvx --from plone.meta config-package --branch current .``.
195
+
196
+ Quality assurance
197
+ -----------------
198
+
199
+ This product fills the following quality criteria:
200
+
201
+ - Unit tests provided
202
+
203
+ - Good documentation provided
204
+
205
+ - Commented code
206
+
207
+ - PyPi eggs provided
208
+
209
+ Author
210
+ ------
211
+
212
+ - Mikko Ohtamaa `<http://opensourcehacker.com> <http://opensourcehacker.com>`_
213
+
214
+ - Quintagroup
215
+
216
+ - Sune Brøndum Wøller
217
+
218
+ - The original concept and code was created by Tomasz J.
219
+ Kotarba <tomasz@kotarba.net> of `SYSTEM7 <http://system7.IT>`_.
220
+
221
+ - ``Twinapex Research, Oulu, Finland <http://www.twinapex.com>``\ \_ -
222
+ High quality Python hackers for hire
223
+
224
+
225
+
226
+ Changelog
227
+ =========
228
+
229
+ 2.0.0 (2026-11-18)
230
+ ------------------
231
+
232
+ Breaking changes:
233
+
234
+ - Native namespace package (PEP 420): ``collective/__init__.py`` is gone.
235
+ Plone 6.1 on Python 3.10 to 3.13, and Plone 6.2 on Python 3.10 to 3.14,
236
+ only. Applications on Python 2 or older Plone releases must stay on 1.1.
237
+ [bsuttor]
238
+
239
+ New features:
240
+
241
+ - Use ``importlib.metadata`` instead of ``pkg_resources``, which setuptools 81+
242
+ deprecates and setuptools 84 (Plone 6.2.3) no longer ships.
243
+ [bsuttor]
244
+
245
+ Internal:
246
+
247
+ - Configure with plone.meta: tox test matrix (Plone 6.2.3 on Python 3.10 to
248
+ 3.14, Plone 6.1 on Python 3.10 to 3.13), GitHub Actions, pre-commit. Package
249
+ metadata moved to ``pyproject.toml``, ``src/`` layout, ``plone.autoinclude``
250
+ entry point.
251
+ [bsuttor]
252
+
253
+ - ``make install`` builds a uv development environment on Plone 6.2.3.
254
+ Travis, buildout configuration and the hand-written GitHub workflow are gone.
255
+ [bsuttor]
256
+
257
+
258
+ 1.1 (2021-08-26)
259
+ ----------------
260
+
261
+ - Add Python 3 & Plone 5.2 compatibility
262
+ [boulch]
263
+
264
+ - Use github CI for automated testing
265
+ [tomgross]
266
+
267
+
268
+ 1.0.3 (2016-02-01)
269
+ ------------------
270
+
271
+ - One final attempt to include HISTORY.txt into egg
272
+ [tomgross]
273
+
274
+
275
+ 1.0.2 (2016-02-01)
276
+ ------------------
277
+
278
+ - Fix brown bag release part 2
279
+ [tomgross]
280
+
281
+ 1.0.1 (2016-02-01)
282
+ ------------------
283
+
284
+ - Fix brown bag release
285
+ [tomgross]
286
+
287
+
288
+ 1.0 (2016-01-30)
289
+ ----------------
290
+
291
+ - Plone 5 compatibility
292
+ [karalics, tomgross]
293
+
294
+
295
+ 0.3 (2013-12-14)
296
+ ----------------
297
+
298
+ * Travis CI integration
299
+ [hvelarde]
300
+
301
+ * Added cron-style tick events, to be triggered by cron or clockserver, with no internal calculation of interval. Updated readme and tests.
302
+ [sunew]
303
+
304
+ 0.2.1 (2012-04-24)
305
+ ------------------
306
+
307
+ * Added logging level option for tick_logger
308
+ [vmaksymiv]
309
+ * Bugfix: data storage
310
+
311
+ 0.2
312
+ ----------------
313
+
314
+ * Added Plone 4 compatibility
315
+ [kroman0]
316
+
317
+ 0.1.1 (2008-11-04)
318
+ ------------------
319
+
320
+ * PyPi egg fixes
321
+
322
+ 0.1
323
+ ----------------
324
+
325
+ * Initial release
326
+
@@ -0,0 +1,11 @@
1
+ collective/timedevents/__init__.py,sha256=F91umWzXeXXVK0ujhPgfW5Pns_G4E-IvtGt7XO3ukAY,88
2
+ collective/timedevents/configure.zcml,sha256=lu7xkCwkS8cHwPWomh0kYrtPnreY9e7DSufDuyTskCo,1296
3
+ collective/timedevents/events.py,sha256=hDGaebAWUXxfNJUv7FVLJSQbdPph7NMy-FPsHYC6gSA,2687
4
+ collective/timedevents/interfaces.py,sha256=nFDcxvTanYw-Xme1HiRL-8pTJeQIaBXCHaNxXxtWeX8,1905
5
+ collective/timedevents/tests.py,sha256=QrqjrhMPC1DWGty-Efsw3Kn0BbgJ8h5WJK_KDZQ9kVI,5230
6
+ collective/timedevents/views.py,sha256=U4jj8YdF4-PRIN1Gyx0c8o0LSlaPDNVJy0j_cZHRmTg,6595
7
+ collective_timedevents-2.0.0.dist-info/METADATA,sha256=SjlBHSE43qwjRgaYgsX4hYoL1vEKwoTfhM3av_kHkfE,9159
8
+ collective_timedevents-2.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
9
+ collective_timedevents-2.0.0.dist-info/entry_points.txt,sha256=ue9oriqwbY5mDverBYmB-21XfmR2FdG-YWncKEEp-pE,42
10
+ collective_timedevents-2.0.0.dist-info/top_level.txt,sha256=FyC0xnd95fkjCaKazR3nfIgNqhWMpB0mYBlzALyXKTg,11
11
+ collective_timedevents-2.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [plone.autoinclude.plugin]
2
+ target = plone
@@ -0,0 +1 @@
1
+ collective