Beispiel #1
0
    def __init__(self, app, task, last_run_at=None):
        self.model = task
        self.app = app

        self.name = task.name
        self.task = task.procedure
        self.schedule = task.schedule.schedule

        self.args = task.arguments
        if not isinstance(self.args, list):
            self.args = []
        self.kwargs = task.keyword_arguments
        if not isinstance(self.kwargs, dict):
            self.kwargs = {}
        self.options = task.options
        self.total_run_count = task.run_count

        if task.last_run_time:
            stamp = task.last_run_time
            if is_naive(stamp):
                stamp = stamp.replace(tzinfo=_tz_local)
            self.last_run_at = stamp.astimezone(_tz_utc
                                                if self.app.conf.enable_utc
                                                else _tz_local)
        else:
            self.last_run_at = last_run_at or self._default_now()
            task.last_run_time = self.last_run_at.replace(
                    tzinfo=(_tz_utc
                            if self.app.conf.enable_utc
                            else _tz_local)).astimezone(_tz_local)

        if not is_naive(self.last_run_at):
            self.last_run_at = self.last_run_at.replace(tzinfo=None)
        self.total_run_count = task.run_count
Beispiel #2
0
 def __init__(self, model, session=None):
     self.app = current_app
     self.session = session or db.session
     self.name = model.name
     self.task = model.task
     self.schedule = model.schedule
     self.args = json.loads(model.args or '[]')
     self.kwargs = json.loads(model.kwargs or '{}')
     self.total_run_count = model.total_run_count
     self.model = model
     self.options = {}  # need reconstruction
     if not model.last_run_at:
         model.last_run_at = self._default_now()
     orig = self.last_run_at = model.last_run_at
     if not is_naive(self.last_run_at):
         self.last_run_at = self.last_run_at.replace(tzinfo=None)
     assert orig.hour == self.last_run_at.hour  # timezone sanity
    def  __init__(self, model):
        self.app = current_app._get_current_object()
        self.name = model.name
        self.task = model.task
        self.schedule = model.schedule
        self.args = model.args
        self.kwargs = model.kwargs
        self.options = dict(
            queue=model.queue,
            exchange=model.exchange,
            routing_key=model.routing_key,
            expires=model.expires,
        )
        self.total_run_count = model.total_run_count
        self.model = model

        if not model.last_run_at:
            model.last_run_at = self._default_now()
        orig = self.last_run_at = model.last_run_at
        if not is_naive(self.last_run_at):
            self.last_run_at = self.last_run_at.replace(tzinfo=None)
        assert orig.hour == self.last_run_at.hour  # timezone sanity
Beispiel #4
0
    def __init__(self, model, app=None):
        self.app = app or current_app._get_current_object()
        self.name = model.name
        self.task = model.task
        try:
            self.schedule = model.schedule
        except model.DoesNotExist:
            logger.error(
                'Disabling schedule %s that was removed from database',
                self.name,
            )
            self._disable(model)
        try:
            self.args = loads(model.args or '[]')
            self.kwargs = loads(model.kwargs or '{}')
        except ValueError as exc:
            logger.exception(
                'Removing schedule %s for argument deseralization error: %r',
                self.name,
                exc,
            )
            self._disable(model)

        self.options = {
            'queue': model.queue,
            'exchange': model.exchange,
            'routing_key': model.routing_key,
            'expires': model.expires,
        }
        self.total_run_count = model.total_run_count
        self.model = model

        if not model.last_run_at:
            model.last_run_at = self._default_now()
        orig = self.last_run_at = model.last_run_at
        if not is_naive(self.last_run_at):
            self.last_run_at = self.last_run_at.replace(tzinfo=None)
        assert orig.hour == self.last_run_at.hour  # timezone sanity