Python celery.current_app._get_current_object() Examples

The following are 4 code examples of celery.current_app._get_current_object(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module celery.current_app , or try the search function .
Example #1
Source File: sqlalchemy_scheduler.py    From celery_sqlalchemy_scheduler with MIT License 6 votes vote down vote up
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 
Example #2
Source File: alert_schedule_entry.py    From MozDef with Mozilla Public License 2.0 5 votes vote down vote up
def __init__(self, task):
        self._task = task

        self.app = current_app._get_current_object()
        self.name = self._task.name
        self.task = self._task.task

        self.enabled = self._task.enabled
        self.schedule_str = self._task.schedule_str
        self.schedule_type = self._task.schedule_type
        self.schedule = self._task.schedule

        self.args = self._task.args
        self.kwargs = self._task.kwargs
        self.options = {
            'queue': self._task.queue,
            'exchange': self._task.exchange,
            'routing_key': self._task.routing_key,
            'expires': self._task.expires
        }
        if self._task.total_run_count is None:
            self._task.total_run_count = 0
        self.total_run_count = self._task.total_run_count

        if not self._task.last_run_at:
            self.last_run_at = self._default_now()
        else:
            self.last_run_at = self._task.last_run_at 
Example #3
Source File: schedulers.py    From celerybeat-mongo with Apache License 2.0 5 votes vote down vote up
def __init__(self, task):
        self._task = task

        self.app = current_app._get_current_object()
        self.name = self._task.name
        self.task = self._task.task

        self.schedule = self._task.schedule

        self.args = self._task.args
        self.kwargs = self._task.kwargs
        self.options = {
            'queue': self._task.queue,
            'exchange': self._task.exchange,
            'routing_key': self._task.routing_key,
            'expires': self._task.expires,
            'soft_time_limit': self._task.soft_time_limit,
            'enabled': self._task.enabled
        }
        if self._task.total_run_count is None:
            self._task.total_run_count = 0
        self.total_run_count = self._task.total_run_count

        if not self._task.last_run_at:
            self._task.last_run_at = self._default_now()
        self.last_run_at = self._task.last_run_at 
Example #4
Source File: schedulers.py    From celery-sqlalchemy-scheduler with MIT License 4 votes vote down vote up
def __init__(self, model, Session, app=None, **kw):
        """Initialize the model entry."""
        self.app = app or current_app._get_current_object()
        self.session = kw.get('session')
        self.Session = Session

        self.model = model
        self.name = model.name
        self.task = model.task

        try:
            self.schedule = model.schedule
            logger.debug('schedule: {}'.format(self.schedule))
        except Exception as e:
            logger.error(e)
            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 = {}
        for option in ['queue', 'exchange', 'routing_key', 'expires',
                       'priority']:
            value = getattr(model, option)
            if value is None:
                continue
            self.options[option] = value

        self.total_run_count = model.total_run_count
        self.enabled = model.enabled

        if not model.last_run_at:
            model.last_run_at = self._default_now()
        self.last_run_at = model.last_run_at

        # 因为从数据库读取的 last_run_at 可能没有时区信息,所以这里必须加上时区信息
        # self.last_run_at = self.last_run_at.replace(tzinfo=self.app.timezone)

        # self.options['expires'] 同理
        # if 'expires' in self.options:
        #     expires = self.options['expires']
        #     self.options['expires'] = expires.replace(tzinfo=self.app.timezone)