File: scheduling.rst

package info (click to toggle)
errbot 6.2.0%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,796 kB
  • sloc: python: 11,557; makefile: 164; sh: 97
file content (43 lines) | stat: -rw-r--r-- 1,195 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Scheduling
==========


Calling a function at a regular interval
----------------------------------------

It's possible to automatically call functions at regular intervals,
using the :meth:`~errbot.botplugin.BotPlugin.start_poller` and
:meth:`~errbot.botplugin.BotPlugin.stop_poller` methods.

For example, you could schedule a callback to be executed once every
minute when your plugin gets activated:

.. code-block:: python
   :emphasize-lines: 9

    from errbot import BotPlugin

    class PluginExample(BotPlugin):
        def my_callback(self):
            self.log.debug('I am called every minute')

        def activate(self):
            super().activate()
            self.start_poller(60, self.my_callback)


It is also possible to specify the `times` parameter, which denotes how
many times the function should be called, for instance:

.. code-block:: python
   :emphasize-lines: 9

    from errbot import BotPlugin

    class PluginExample(BotPlugin):
        def my_callback(self):
            self.log.debug('I got called after a minute (and just once)')

        def activate(self):
            super().activate()
            self.start_poller(60, self.my_callback, times=1)