| 1 |
Scheduling |
| 2 |
========== |
| 3 |
|
| 4 |
|
| 5 |
Calling a function at a regular interval |
| 6 |
---------------------------------------- |
| 7 |
|
| 8 |
It's possible to automatically call functions at regular intervals, |
| 9 |
using the :meth:`~errbot.botplugin.BotPlugin.start_poller` and |
| 10 |
:meth:`~errbot.botplugin.BotPlugin.stop_poller` methods. |
| 11 |
|
| 12 |
For example, you could schedule a callback to be executed once every |
| 13 |
minute when your plugin gets activated: |
| 14 |
|
| 15 |
.. code-block:: python |
| 16 |
:emphasize-lines: 9 |
| 17 |
|
| 18 |
from errbot import BotPlugin |
| 19 |
|
| 20 |
class PluginExample(BotPlugin): |
| 21 |
def my_callback(self): |
| 22 |
self.log.debug('I am called every minute') |
| 23 |
|
| 24 |
def activate(self): |
| 25 |
super().activate() |
| 26 |
self.start_poller(60, self.my_callback) |
| 27 |
|
| 28 |
|
| 29 |
It is also possible to specify the `times` parameter, which denotes how |
| 30 |
many times the function should be called, for instance: |
| 31 |
|
| 32 |
.. code-block:: python |
| 33 |
:emphasize-lines: 9 |
| 34 |
|
| 35 |
from errbot import BotPlugin |
| 36 |
|
| 37 |
class PluginExample(BotPlugin): |
| 38 |
def my_callback(self): |
| 39 |
self.log.debug('I got called after a minute (and just once)') |
| 40 |
|
| 41 |
def activate(self): |
| 42 |
super().activate() |
| 43 |
self.start_poller(60, self.my_callback, times=1) |