Skip to main content

Plone/Zope time based event mechanism

Project description

collective.timedevents

Overview

collective.timedevents fires clock based Zope 3 events. They can make Zope application react to timers. This is useful for creating services where something must happen regurlarly or after a certain period has expired.

This is a developer level product. This product is indended to replace Products.TickingMachine with more robust Zope 3 codebase.

There are two different styles of using it:

  1. Using the ITickEvent and calculating if action needs to be done in the event subscriber. This will also take care of timing over zope restarts by keeping event timing persistent.

  2. Subscribing to any of the cron-style IIntervalTicks*-events, not worrying about the timing client side. For the longer ticks (weekly, montly) a cron-job as trigger makes most sense, in case of zope restarts.

Tested by Travis:

https://secure.travis-ci.org/collective/collective.timedevents.png?branch=master

Installation

  1. Add collective.timedevents to your buildout by adding the egg to your buildout.cfg:

    eggs =
       ...
       collective.timedevents
  2. Trigger

Can either be cron-jobs or zope clock-server.

Add clock server to tick timedevents subscribers - use your Plone instance name:

[instance]
...
    zope-conf-additional =
    <clock-server>
        method /mysite/@@tick
        period 90
        user clockserver-user
        password password
        host localhost
    </clock-server>

Or for the cron-like interval-based events, here 900 seconds for the 15-minute event:

<clock-server>
  method /mysite/@@tick_fifteen
  period 900
  user clockserver-user
  password password
  host localhost
</clock-server>

Now you should start to see ticks in the zope event log.

Usage

Subscribe to the events/ticks you need.

  1. Using the ITickEvent method:

  1. Add collective.timedevents.interfaces.ITickEvent subscribers to your product ZCML declarations:

    <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>
  2. Configure your event handler to react after certain period has expired:

    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
  1. Using the IIntervalTicks*-events:

Add collective.timedevents.interfaces.IIntervalTicks* subscribers to your module ZCML declarations:

<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>

Other

All ticking code is executed under admin privileges.

ITickEvent tick period is 300 seconds by default. This can be controlled in views.py.

Ticks for ITickEvent are logged by events.tick_logger defined in configure.zcml.

Quality assurance

This product fills the following quality criteria:

  • Unit tests provided

  • Good documentation provided

  • Commented code

  • PyPi eggs provided

Author

  • Mikko Ohtamaa <http://opensourcehacker.com>

  • Quintagroup

  • Sune Brøndum Wøller

  • The orignal concept and code was created by Tomasz J. Kotarba <tomasz@kotarba.net> of SYSTEM7.

  • Twinapex Research, Oulu, Finland <http://www.twinapex.com>_ - High quality Python hackers for hire

Changelog

1.1 (2021-08-26)

  • Add Python 3 & Plone 5.2 compatibility [boulch]

  • Use github CI for automated testing [tomgross]

1.0.3 (2016-02-01)

  • One final attempt to include HISTORY.txt into egg [tomgross]

1.0.2 (2016-02-01)

  • Fix brown bag release part 2 [tomgross]

1.0.1 (2016-02-01)

  • Fix brown bag release [tomgross]

1.0 (2016-01-30)

  • Plone 5 compatibility [karalics, tomgross]

0.3 (2013-12-14)

  • Travis CI integration [hvelarde]

  • Added cron-style tick events, to be triggered by cron or clockserver, with no internal calculation of interval. Updated readme and tests. [sunew]

0.2.1 (2012-04-24)

  • Added logging level option for tick_logger [vmaksymiv]

  • Bugfix: data storage

0.2

  • Added Plone 4 compatibility [kroman0]

0.1.1 (2008-11-04)

  • PyPi egg fixes

0.1

  • Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

collective.timedevents-1.1.tar.gz (12.5 kB view details)

Uploaded Source

File details

Details for the file collective.timedevents-1.1.tar.gz.

File metadata

  • Download URL: collective.timedevents-1.1.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.11

File hashes

Hashes for collective.timedevents-1.1.tar.gz
Algorithm Hash digest
SHA256 df5498a76ebfe099576da253d9e2f4b1d33b31ccc488a777d0d7b18fde7afcc2
MD5 d2ad8ea7ff1ba62b90a65c529aaea5fc
BLAKE2b-256 e307df9b0fe0fdefc02b31af70b57f601e72110a423dad07f0731337b245f7bb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page