Welcome to Errcron’s documentation!¶
Contents¶
Introduction¶
Errcron is extension package to implement behavior of Crontab for Errbot plugins.
Installation¶
Dependencies¶
Errcron is implemented as abstract class for plugin, so it is required Errbot.
And, for run with errcron, it depend on follow packages:
- six
- crontab
Install¶
Basic installation is to use pip.
$ pip install errcron
If you want to use latest master rivision, install from github.
$ pip install https://github.com/attakei/errcron/archive/master.zip
Sample usage¶
Simply usage¶
from errbot import BotPlugin
from errcron.bot import CrontabMixin
class Crontab(BotPlugin, CrontabMixin):
CRONTAB = [
'0 8 * * * .post_morning_call'
]
def activate(self):
super().activate()
self.activate_crontab()
def morning_meeting(self, polled_time):
user = self.build_identifier('#general')
return self.send(user, 'Just {} o-clock!!'.format(polled_time.strftime('%H')))
- Using crontab bot plugin must be extended by CrontabMixin.
And call
activate_crontab
in activation plugin. - Define schedule and job as like as crontab in
CRONTAB
property in bot-plugin class. - Cronjob function has least one arguments.
polled_time
is datetime instance of time called in function.
Crontab scheduling¶
errcron use crontab like job scheduliing. See crontab page in PyPI
Set timezone¶
If scheduling timezone is not same machine timezone, you can change timezone settings in plugin.
To use, set timezone string for TIMEZONE
property in plugin class.
class Crontab(BotPlugin, CrontabMixin):
TIMEZONE = 'America/New_York'
You can set timezone config.py
instead of plugin class.
All changelogs¶
For version 0.4.x¶
version 0.4.1¶
- Fix missing dependencies
version 0.4¶
- Enable class TIMEZONE definition
- Set order of extends
All versions¶
Version 0.1.0¶
- Released
Version 0.3.0¶
- Implement crontab format.
- Implement be able to run instance method of plugin.
- Change plling interval
Version 0.3.1(not build)¶
- Show documents by Read The Doc
Version 0.4.0¶
- Enable class TIMEZONE definition
- Set order of extends
Version 0.4.1¶
- Fix missing dependencies
version 0.4.3¶
- Add python 3.6 for test target (compatible)
- Can import as
from errcron import CrontabMixin
version 0.4.4¶
- Fix for latest crontab-parser
- Fix test targets in Travis-CI
API documentation¶
errcron package¶
Submodules¶
errcron.action module¶
Bot actions
-
errcron.action.
post_message
(plugin, polled_time, identity, message)¶ Post single message
errcron.bot module¶
Bot class extensions
-
class
errcron.bot.
CrontabMixin
¶ Bases:
object
Mix-in class to implement crontab features
If you will use crontab by it, call activate_crontab
-
activate
()¶
-
activate_crontab
()¶ Activate polling function and register first crontab
-
load_job_from_string
(spec)¶
-
poll_crontab
()¶ Check crontab and run target jobs
-
errcron.cronjob module¶
-
class
errcron.cronjob.
CronJob
¶ Bases:
object
Job runner for errcron, handling job running trigger and action
-
do_action
(plugin, do_time)¶ Run cronjob action with plugin
Parameters: - plugin (errbot.BotPlugin) – running Errbot plugin
- do_time (datetime.datetime) – action triggered time
Returns: Returned value from action
-
is_runnable
(time)¶ Check whether job run action at specified time
Parameters: time (datetime.datetime) – Time to run action Returns: Job is runnable or not Return type: boolean
-
set_action
(action, *args)¶ Set action and arguments to run in triggered time
Parameters: - action (str) – function path as anction
- args (list or tuple) – function arguments
-
set_crontab
(crontab)¶
-
set_triggers
(trigger_format, trigger_time)¶ Set trigger_format and trigger_time (recommend)
Parameters: - trigger_format (basestring) – datetime format used by strftime
- trigger_format – datetime values returned by strftime
Raises: ValueError
-
-
errcron.cronjob.
load_from_string
(crontab, format='crontab')¶ Load cronjob from single string
Parameters: - crontab (str) – crontab string(trigger_format, trigger_time, function, args)
- format (str) – job trigger type
Returns: Cronjob
Return type:
-
errcron.cronjob.
parse_crontab
(crontab)¶
Module contents¶
-
class
errcron.
CrontabMixin
¶ Bases:
object
Mix-in class to implement crontab features
If you will use crontab by it, call activate_crontab
-
activate
()¶
-
activate_crontab
()¶ Activate polling function and register first crontab
-
load_job_from_string
(spec)¶
-
poll_crontab
()¶ Check crontab and run target jobs
-