|
@@ -1,8 +1,3 @@
|
|
|
-"""
|
|
|
-
|
|
|
-Periodic Task Scheduler
|
|
|
-
|
|
|
-"""
|
|
|
import errno
|
|
|
import os
|
|
|
import time
|
|
@@ -37,38 +32,37 @@ class SchedulingError(Exception):
|
|
|
class ScheduleEntry(object):
|
|
|
"""An entry in the scheduler.
|
|
|
|
|
|
- :param name: see :attr:`name`.
|
|
|
- :param schedule: see :attr:`schedule`.
|
|
|
- :param args: see :attr:`args`.
|
|
|
- :param kwargs: see :attr:`kwargs`.
|
|
|
+ :keyword name: see :attr:`name`.
|
|
|
+ :keyword schedule: see :attr:`schedule`.
|
|
|
+ :keyword args: see :attr:`args`.
|
|
|
+ :keyword kwargs: see :attr:`kwargs`.
|
|
|
+ :keyword options: see :attr:`options`.
|
|
|
:keyword last_run_at: see :attr:`last_run_at`.
|
|
|
:keyword total_run_count: see :attr:`total_run_count`.
|
|
|
+ :keyword relative: Is the time relative to when the server starts?
|
|
|
|
|
|
- .. attribute:: name
|
|
|
-
|
|
|
- The task name.
|
|
|
-
|
|
|
- .. attribute:: schedule
|
|
|
-
|
|
|
- The schedule (run_every/crontab)
|
|
|
-
|
|
|
- .. attribute:: args
|
|
|
-
|
|
|
- Args to apply.
|
|
|
+ """
|
|
|
|
|
|
- .. attribute:: kwargs
|
|
|
+ #: The task name
|
|
|
+ name = None
|
|
|
|
|
|
- Keyword arguments to apply.
|
|
|
+ #: The schedule (run_every/crontab)
|
|
|
+ schedule = None
|
|
|
|
|
|
- .. attribute:: last_run_at
|
|
|
+ #: Positional arguments to apply.
|
|
|
+ args = None
|
|
|
|
|
|
- The time and date of when this task was last run.
|
|
|
+ #: Keyword arguments to apply.
|
|
|
+ kwargs = None
|
|
|
|
|
|
- .. attribute:: total_run_count
|
|
|
+ #: Task execution options.
|
|
|
+ options = None
|
|
|
|
|
|
- Total number of times this periodic task has been executed.
|
|
|
+ #: The time and date of when this task was last scheduled.
|
|
|
+ last_run_at = None
|
|
|
|
|
|
- """
|
|
|
+ #: Total number of times this task has been scheduled.
|
|
|
+ total_run_count = 0
|
|
|
|
|
|
def __init__(self, name=None, task=None, last_run_at=None,
|
|
|
total_run_count=None, schedule=None, args=(), kwargs={},
|
|
@@ -112,34 +106,29 @@ class ScheduleEntry(object):
|
|
|
return vars(self).iteritems()
|
|
|
|
|
|
def __repr__(self):
|
|
|
- return "<Entry: %s %s(*%s, **%s) {%s}>" % (self.name,
|
|
|
- self.task,
|
|
|
- self.args,
|
|
|
- self.kwargs,
|
|
|
- self.schedule)
|
|
|
+ return "<Entry: %s %s(*%s, **%s) {%s}>" % (
|
|
|
+ self.name, self.task, self.args, self.kwargs, self.schedule)
|
|
|
|
|
|
|
|
|
class Scheduler(object):
|
|
|
"""Scheduler for periodic tasks.
|
|
|
|
|
|
:keyword schedule: see :attr:`schedule`.
|
|
|
- :keyword logger: see :attr:`logger`.
|
|
|
+ :keyword logger: see :attr:`logger`.
|
|
|
:keyword max_interval: see :attr:`max_interval`.
|
|
|
|
|
|
- .. attribute:: schedule
|
|
|
-
|
|
|
- The schedule dict/shelve.
|
|
|
-
|
|
|
- .. attribute:: logger
|
|
|
+ """
|
|
|
|
|
|
- The logger to use.
|
|
|
+ Entry = ScheduleEntry
|
|
|
|
|
|
- .. attribute:: max_interval
|
|
|
+ #: The schedule dict/shelve.
|
|
|
+ schedule = None
|
|
|
|
|
|
- Maximum time to sleep between re-checking the schedule.
|
|
|
+ #: Current logger.
|
|
|
+ logger = None
|
|
|
|
|
|
- """
|
|
|
- Entry = ScheduleEntry
|
|
|
+ #: Maximum time to sleep between re-checking the schedule.
|
|
|
+ max_interval = 1
|
|
|
|
|
|
def __init__(self, schedule=None, logger=None, max_interval=None,
|
|
|
app=None, Publisher=None, lazy=False, **kwargs):
|
|
@@ -351,8 +340,7 @@ class PersistentScheduler(Scheduler):
|
|
|
class Service(object):
|
|
|
scheduler_cls = PersistentScheduler
|
|
|
|
|
|
- def __init__(self, logger=None,
|
|
|
- max_interval=None, schedule_filename=None,
|
|
|
+ def __init__(self, logger=None, max_interval=None, schedule_filename=None,
|
|
|
scheduler_cls=None, app=None):
|
|
|
self.app = app_or_default(app)
|
|
|
self.max_interval = max_interval or \
|