def __init__(self, model): self.app = current_app._get_current_object() self.name = model.name self.task = model.task self.schedule = model.schedule try: self.args = loads(model.args or '[]') self.kwargs = loads(model.kwargs or '{}') except ValueError: logging.error('Failed to serialize arguments for %s.', self.name, exc_info=1) logging.warning('Disabling %s', self.name) model.no_changes = True model.enabled = False model.save() expires = model.expires or model.expires_at self.options = { 'queue': model.queue, 'exchange': model.exchange, 'routing_key': model.routing_key, 'expires': 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
def __init__(self, model): self.app = current_app._get_current_object() self.name = model.name self.task = model.task try: self.schedule = model.schedule except model.DoesNotExist: logger.error('Schedule was removed from database') logger.warning('Disabling %s', self.name) self._disable(model) try: self.args = loads(model.args or '[]') self.kwargs = loads(model.kwargs or '{}') except ValueError: logging.error('Failed to serialize arguments for %s.', self.name, exc_info=1) logging.warning('Disabling %s', self.name) 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
def __init__(self, model): self.app = current_app._get_current_object() self.name = model.name self.task = model.task self.schedule = model.schedule try: self.args = loads(model.args or '[]') self.kwargs = loads(model.kwargs or '{}') except ValueError: # disable because of error deserializing args/kwargs model.no_changes = True model.enabled = False model.save() raise 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
def __init__(self, model): self.app = current_app._get_current_object() self.name = model.name self.task = model.task try: self.schedule = model.schedule except model.DoesNotExist: logger.error('Schedule was removed from database') logger.warning('Disabling %s', self.name) self._disable(model) try: self.args = loads(model.args or '[]') self.kwargs = loads(model.kwargs or '{}') except ValueError: logging.error('Failed to serialize arguments for %s.', self.name, exc_info=1) logging.warning('Disabling %s', self.name) 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
def __init__(self, model): self.app = current_app._get_current_object() self.name = model.name self.task = model.task self.schedule = model.schedule try: self.args = deserialize(model.args or u'[]') self.kwargs = deserialize(model.kwargs or u'{}') except ValueError: logging.error('Failed to serialize arguments for %s.', self.name, exc_info=1) logging.warning('Disabling %s', self.name) model.no_changes = True model.enabled = False model.save() 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
def __init__(self, model): self.app = current_app._get_current_object() self.name = model.name self.task = model.task self.schedule = model.schedule try: self.args = loads(model.args or "[]") self.kwargs = loads(model.kwargs or "{}") except ValueError: logging.error("Failed to serialize arguments for %s.", self.name, exc_info=1) logging.warning("Disabling %s", self.name) model.no_changes = True model.enabled = False model.save() 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
def __init__(self, model, session=None): self.app = current_app self.session = session or get_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
def maybe_make_aware(self, dt): if not is_naive(dt): return dt return make_aware(dt, self.tz)