當前位置: 首頁>>代碼示例>>Python>>正文


Python schedules.schedule方法代碼示例

本文整理匯總了Python中celery.schedules.schedule方法的典型用法代碼示例。如果您正苦於以下問題:Python schedules.schedule方法的具體用法?Python schedules.schedule怎麽用?Python schedules.schedule使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在celery.schedules的用法示例。


在下文中一共展示了schedules.schedule方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: from_entry

# 需要導入模塊: from celery import schedules [as 別名]
# 或者: from celery.schedules import schedule [as 別名]
def from_entry(cls, name, session, skip_fields=('relative', 'options'), **entry):
        """
        PeriodicTask
        :param session:
        :param name:
        :param skip_fields:
        :param entry:
        :return:
        """
        fields = dict(entry)
        for skip_field in skip_fields:
            fields.pop(skip_field, None)
        schedule = fields.pop('schedule')
        model_schedule, model_field = cls.to_model_schedule(schedule, session)
        fields[model_field] = model_schedule
        fields['args'] = json.dumps(fields.get('args') or [])
        fields['kwargs'] = json.dumps(fields.get('kwargs') or {})
        model, _ = PeriodicTask.update_or_create(session, name=name, defaults=fields)
        cls.save_model(session, model)
        return cls(model) 
開發者ID:Salamek,項目名稱:gitlab-tools,代碼行數:22,代碼來源:schedulers.py

示例2: from_schedule

# 需要導入模塊: from celery import schedules [as 別名]
# 或者: from celery.schedules import schedule [as 別名]
def from_schedule(cls, dbsession, schedule):
        spec = {'minute': schedule._orig_minute,
                'hour': schedule._orig_hour,
                'day_of_week': schedule._orig_day_of_week,
                'day_of_month': schedule._orig_day_of_month,
                'month_of_year': schedule._orig_month_of_year}
        try:
            query = dbsession.query(CrontabSchedule)
            query = query.filter_by(**spec)
            existing = query.one()
            return existing
        except NoResultFound:
            return cls(**spec)
        except MultipleResultsFound:
            query = dbsession.query(CrontabSchedule)
            query = query.filter_by(**spec)
            query.delete()
            dbsession.commit()
            return cls(**spec) 
開發者ID:tuomur,項目名稱:celery_sqlalchemy_scheduler,代碼行數:21,代碼來源:sqlalchemy_scheduler_models.py

示例3: from_entry

# 需要導入模塊: from celery import schedules [as 別名]
# 或者: from celery.schedules import schedule [as 別名]
def from_entry(cls, name, skip_fields=('relative', 'options'), **entry):
        options = entry.get('options') or {}
        fields = dict(entry)
        for skip_field in skip_fields:
            fields.pop(skip_field, None)
        schedule = fields.pop('schedule')
        model_schedule, model_field = cls.to_model_schedule(schedule)
        fields[model_field] = model_schedule
        fields['args'] = fields.get('args') or []
        fields['kwargs'] = fields.get('kwargs') or {}
        fields['queue'] = options.get('queue')
        fields['exchange'] = options.get('exchange')
        fields['routing_key'] = options.get('routing_key')

        query = dbsession.query(DatabaseSchedulerEntry)
        query = query.filter_by(name=name)
        db_entry = query.first()
        if db_entry is None:
            new_entry = DatabaseSchedulerEntry(**fields)
            new_entry.name = name
            dbsession.add(new_entry)
            dbsession.commit()
            db_entry = new_entry
        return cls(db_entry) 
開發者ID:tuomur,項目名稱:celery_sqlalchemy_scheduler,代碼行數:26,代碼來源:sqlalchemy_scheduler.py

示例4: from_schedule

# 需要導入模塊: from celery import schedules [as 別名]
# 或者: from celery.schedules import schedule [as 別名]
def from_schedule(cls, session, schedule):
        spec = {
            'minute': schedule._orig_minute,
            'hour': schedule._orig_hour,
            'day_of_week': schedule._orig_day_of_week,
            'day_of_month': schedule._orig_day_of_month,
            'month_of_year': schedule._orig_month_of_year,
        }
        if schedule.tz:
            spec.update({
                'timezone': schedule.tz.zone
            })
        model = session.query(CrontabSchedule).filter_by(**spec).first()
        if not model:
            model = cls(**spec)
            session.add(model)
            session.commit()
        return model 
開發者ID:AngelLiang,項目名稱:celery-sqlalchemy-scheduler,代碼行數:20,代碼來源:models.py

示例5: _unpack_fields

# 需要導入模塊: from celery import schedules [as 別名]
# 或者: from celery.schedules import schedule [as 別名]
def _unpack_fields(cls, session, schedule,
                       args=None, kwargs=None, relative=None, options=None,
                       **entry):
        """

        **entry sample:

            {'task': 'celery.backend_cleanup',
             'schedule': <crontab: 0 4 * * * (m/h/d/dM/MY)>,
             'options': {'expires': 43200}}

        """
        model_schedule, model_field = cls.to_model_schedule(session, schedule)
        entry.update(
            # the model_id which to relationship
            {model_field + '_id': model_schedule.id},
            args=dumps(args or []),
            kwargs=dumps(kwargs or {}),
            **cls._unpack_options(**options or {})
        )
        return entry 
開發者ID:AngelLiang,項目名稱:celery-sqlalchemy-scheduler,代碼行數:23,代碼來源:schedulers.py

示例6: all_as_schedule

# 需要導入模塊: from celery import schedules [as 別名]
# 或者: from celery.schedules import schedule [as 別名]
def all_as_schedule(self):
        # TODO:
        session = self.Session()
        with session_cleanup(session):
            logger.debug('DatabaseScheduler: Fetching database schedule')
            # get all enabled PeriodicTask
            models = session.query(self.Model).filter_by(enabled=True).all()
            s = {}
            for model in models:
                try:
                    s[model.name] = self.Entry(model,
                                               app=self.app,
                                               Session=self.Session,
                                               session=session)
                except ValueError:
                    pass
            return s 
開發者ID:AngelLiang,項目名稱:celery-sqlalchemy-scheduler,代碼行數:19,代碼來源:schedulers.py

示例7: sync

# 需要導入模塊: from celery import schedules [as 別名]
# 或者: from celery.schedules import schedule [as 別名]
def sync(self):
        """override"""
        logger.info('Writing entries...')
        _tried = set()
        _failed = set()
        try:
            while self._dirty:
                name = self._dirty.pop()
                try:
                    self.schedule[name].save()  # save to database
                    logger.debug(
                        '{name} save to database'.format(name=name))
                    _tried.add(name)
                except (KeyError) as exc:
                    logger.error(exc)
                    _failed.add(name)
        except sqlalchemy.exc.IntegrityError as exc:
            logger.exception('Database error while sync: %r', exc)
        except Exception as exc:
            logger.exception(exc)
        finally:
            # retry later, only for the failed ones
            self._dirty |= _failed 
開發者ID:AngelLiang,項目名稱:celery-sqlalchemy-scheduler,代碼行數:25,代碼來源:schedulers.py

示例8: schedule

# 需要導入模塊: from celery import schedules [as 別名]
# 或者: from celery.schedules import schedule [as 別名]
def schedule(self):
        initial = update = False
        if self._initial_read:
            logger.debug('DatabaseScheduler: initial read')
            initial = update = True
            self._initial_read = False
        elif self.schedule_changed():
            # when you updated the `PeriodicTasks` model's `last_update` field
            logger.info('DatabaseScheduler: Schedule changed.')
            update = True

        if update:
            self.sync()
            self._schedule = self.all_as_schedule()
            # the schedule changed, invalidate the heap in Scheduler.tick
            if not initial:
                self._heap = []
                self._heap_invalidated = True
            if logger.isEnabledFor(logging.DEBUG):
                logger.debug('Current schedule:\n%s', '\n'.join(
                    repr(entry) for entry in values(self._schedule)),
                )
        # logger.debug(self._schedule)
        return self._schedule 
開發者ID:AngelLiang,項目名稱:celery-sqlalchemy-scheduler,代碼行數:26,代碼來源:schedulers.py

示例9: test_serialize_entry_json_serializable

# 需要導入模塊: from celery import schedules [as 別名]
# 或者: from celery.schedules import schedule [as 別名]
def test_serialize_entry_json_serializable(dt):
    entry = ScheduleEntry(
        name='entry-1',
        task='entry-1-task',
        schedule=dt,
        args=('arg1', 'arg2'),
        kwargs={'key1': 'val1', 'key2': 'val2'},
        last_run_at=datetime.now(),
        total_run_count=1,
        options={},
    )

    obj = serialize_entry(entry)

    try:
        json.dumps(obj)
    except Exception as e:
        pytest.fail(e) 
開發者ID:mixkorshun,項目名稱:celery-beatx,代碼行數:20,代碼來源:test_serializer.py

示例10: serialize_entry

# 需要導入模塊: from celery import schedules [as 別名]
# 或者: from celery.schedules import schedule [as 別名]
def serialize_entry(entry):
    """
    Serialize ScheduleEntry to json-valid dictionary.

    Helps serialize entry to json, yml and any other formats.

    :param entry: ScheduleEntry
    :return: json-valid dictionary
    """
    return {
        'name': entry.name,
        'task': entry.task,
        'schedule': encode_schedule(entry.schedule),
        'args': entry.args,
        'kwargs': entry.kwargs,
        'last_run_at': encode_datetime(entry.last_run_at),
        'total_run_count': entry.total_run_count,
        'options': entry.options
    } 
開發者ID:mixkorshun,項目名稱:celery-beatx,代碼行數:21,代碼來源:serializer.py

示例11: deserialize_entry

# 需要導入模塊: from celery import schedules [as 別名]
# 或者: from celery.schedules import schedule [as 別名]
def deserialize_entry(entry):
    """
    Deserialize ScheduleEntry from dictionary.

    Helps deserialize entry from json, yml and any other formats.

    :param entry:
    :return:
    """
    return ScheduleEntry(
        name=entry['name'],
        task=entry['task'],
        schedule=decode_schedule(entry['schedule']),
        args=entry['args'],
        kwargs=entry['kwargs'],
        last_run_at=decode_datetime(entry['last_run_at']),
        total_run_count=entry['total_run_count'],
        options=entry['options'],
    ) 
開發者ID:mixkorshun,項目名稱:celery-beatx,代碼行數:21,代碼來源:serializer.py

示例12: test_parsing_dict

# 需要導入模塊: from celery import schedules [as 別名]
# 或者: from celery.schedules import schedule [as 別名]
def test_parsing_dict(self):
        task = PeriodicTask(**self.task_dict)
        assert task.name == 'bruteforce_ssh.AlertBruteforceSsh'
        assert task.task == 'bruteforce_ssh.AlertBruteforceSsh'
        assert isinstance(task._id, str)
        assert task.args == []
        assert task.kwargs == {}
        assert task.enabled is True
        assert task.queue is None
        assert task.exchange is None
        assert task.routing_key is None
        assert task.last_run_at is None
        assert task.run_immediately is False
        assert task.total_run_count is 0
        assert task.schedule_type == 'interval'
        assert task.schedule_str == '1.0 seconds'
        assert isinstance(task.celery_schedule, Interval) is True
        assert isinstance(task.schedule, celery_sched) is True 
開發者ID:mozilla,項目名稱:MozDef,代碼行數:20,代碼來源:test_periodic_task.py

示例13: schedule

# 需要導入模塊: from celery import schedules [as 別名]
# 或者: from celery.schedules import schedule [as 別名]
def schedule(self):
        return schedules.schedule(datetime.timedelta(**{self.period.code: self.every})) 
開發者ID:Salamek,項目名稱:gitlab-tools,代碼行數:4,代碼來源:celery.py

示例14: from_schedule

# 需要導入模塊: from celery import schedules [as 別名]
# 或者: from celery.schedules import schedule [as 別名]
def from_schedule(cls, session, schedule, period='seconds'):
        every = max(schedule.run_every.total_seconds(), 0)
        obj = cls.filter_by(session, every=every, period=period).first()
        if obj is None:
            return cls(every=every, period=period)
        else:
            return obj 
開發者ID:Salamek,項目名稱:gitlab-tools,代碼行數:9,代碼來源:celery.py

示例15: is_due

# 需要導入模塊: from celery import schedules [as 別名]
# 或者: from celery.schedules import schedule [as 別名]
def is_due(self):
        if not self.model.enabled:
            return False, 5.0   # 5 second delay for re-enable.
        return self.schedule.is_due(self.last_run_at) 
開發者ID:Salamek,項目名稱:gitlab-tools,代碼行數:6,代碼來源:schedulers.py


注:本文中的celery.schedules.schedule方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。