本文整理汇总了Python中celery.beat.Scheduler类的典型用法代码示例。如果您正苦于以下问题:Python Scheduler类的具体用法?Python Scheduler怎么用?Python Scheduler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Scheduler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, *args, **kwargs):
self._dirty = set()
self._finalize = Finalize(self, self.sync, exitpriority=5)
Scheduler.__init__(self, *args, **kwargs)
self.max_interval = (kwargs.get("max_interval")
or self.app.conf.CELERYBEAT_MAX_LOOP_INTERVAL
or DEFAULT_MAX_INTERVAL)
示例2: __init__
def __init__(self, *args, **kwargs):
if hasattr(current_app.conf, "CELERY_MONGODB_SCHEDULER_DB"):
db = current_app.conf.CELERY_MONGODB_SCHEDULER_DB
else:
db = "celery"
if hasattr(current_app.conf, "CELERY_MONGODB_SCHEDULER_COLLECTION") \
and current_app.conf.CELERY_MONGODB_SCHEDULER_COLLECTION:
collection=current_app.conf.CELERY_MONGODB_SCHEDULER_COLLECTION
else:
collection="schedules"
if hasattr(current_app.conf, "CELERY_MONGODB_SCHEDULER_URL"):
connection=Connection(current_app.conf.CELERY_MONGODB_SCHEDULER_URL)
get_logger(__name__).info("backend scheduler using %s/%s:%s",
current_app.conf.CELERY_MONGODB_SCHEDULER_DB,
db,collection)
else:
connection=Connection()
self.db=connection[db][collection]
self._schedule = {}
self._last_updated = None
Scheduler.__init__(self, *args, **kwargs)
self.max_interval = (kwargs.get('max_interval') \
or self.app.conf.CELERYBEAT_MAX_LOOP_INTERVAL or 300)
示例3: __init__
def __init__(self, *args, **kwargs):
self._schedule = {}
self._last_updated = None
Scheduler.__init__(self, *args, **kwargs)
self.max_interval = (kwargs.get('max_interval')
or self.app.conf.CELERYBEAT_MAX_LOOP_INTERVAL or 300)
self.db = db_factory.get_database()
示例4: __init__
def __init__(self, *args, **kwargs):
self._dirty = set()
self._last_flush = None
self._flush_every = 3 * 60
self._finalize = Finalize(self, self.flush, exitpriority=5)
Scheduler.__init__(self, *args, **kwargs)
self.max_interval = 5
示例5: __init__
def __init__(self, *args, **kwargs):
if hasattr(current_app.conf, 'CELERY_REDIS_SCHEDULER_URL'):
logger.info('backend scheduler using %s',
current_app.conf.CELERY_REDIS_SCHEDULER_URL)
else:
logger.info('backend scheduler using %s',
current_app.conf.CELERY_REDIS_SCHEDULER_URL)
# how long we should hold on to the redis lock in seconds
if 'CELERY_REDIS_SCHEDULER_LOCK_TTL' in current_app.conf:
lock_ttl = current_app.conf.CELERY_REDIS_SCHEDULER_LOCK_TTL
else:
lock_ttl = 30
if lock_ttl < self.UPDATE_INTERVAL.seconds:
lock_ttl = self.UPDATE_INTERVAL.seconds * 2
self.lock_ttl = lock_ttl
self._schedule = {}
self._last_updated = None
self._lock_acquired = False
Scheduler.__init__(self, *args, **kwargs)
self.max_interval = (kwargs.get('max_interval') \
or self.app.conf.CELERYBEAT_MAX_LOOP_INTERVAL or 300)
self._lock = rdb.lock('celery:beat:task_lock', timeout=self.lock_ttl)
self._lock_acquired = self._lock.acquire(blocking=False)
self.Entry.scheduler = self
示例6: __init__
def __init__(self, *args, **kwargs):
"""Initialize the database scheduler."""
self._dirty = set()
Scheduler.__init__(self, *args, **kwargs)
self._finalize = Finalize(self, self.sync, exitpriority=5)
self.max_interval = (
kwargs.get('max_interval')
or self.app.conf.beat_max_loop_interval
or DEFAULT_MAX_INTERVAL)
示例7: __init__
def __init__(self, *args, **kwargs):
log.info("SQLAlchemyScheduler.__init__ called")
self._dirty = set()
Scheduler.__init__(self, *args, **kwargs)
self.max_interval = (
kwargs.get('max_interval') or
self.app.conf.CELERYBEAT_MAX_LOOP_INTERVAL or
DEFAULT_MAX_INTERVAL)
示例8: __init__
def __init__(self, *args, **kwargs):
if hasattr(current_app.conf, 'CELERY_REDIS_SCHEDULER_URL'):
get_logger(__name__).info('backend scheduler using %s',
current_app.conf.CELERY_REDIS_SCHEDULER_URL)
else:
get_logger(__name__).info('backend scheduler using %s',
current_app.conf.CELERY_REDIS_SCHEDULER_URL)
self._schedule = {}
self._last_updated = None
Scheduler.__init__(self, *args, **kwargs)
self.max_interval = (kwargs.get('max_interval') \
or self.app.conf.CELERYBEAT_MAX_LOOP_INTERVAL or 300)
示例9: __init__
def __init__(self, *args, **kwargs):
self.data = {}
self.last_refresh = None
if 'LEEK_REDIS_URL' not in current_app.conf:
raise Exception('Missing LEEK_REDIS_URL celery config')
self.hash_key = current_app.conf.get('LEEK_HASH_KEY', 'leek')
self.redis = redis.from_url(current_app.conf.get('LEEK_REDIS_URL'))
self.tz = timezone.get_timezone(current_app.conf.get('CELERY_TIMEZONE', 'UTC'))
Scheduler.__init__(self, *args, **kwargs)
self.max_interval = self.app.conf.get('LEEK_REFRESH_INTERVAL', 5)
self.refresh_frequency = timedelta(seconds=self.max_interval)
示例10: __init__
def __init__(self, *args, **kwargs):
if hasattr(current_app.conf, 'CELERY_REDIS_SCHEDULER_URL'):
logger.info('backend scheduler using %s',
current_app.conf.CELERY_REDIS_SCHEDULER_URL)
else:
logger.info('backend scheduler using %s',
current_app.conf.CELERY_REDIS_SCHEDULER_URL)
self._schedule = {}
self._last_updated = None
Scheduler.__init__(self, *args, **kwargs)
self.max_interval = (kwargs.get('max_interval') \
or self.app.conf.CELERYBEAT_MAX_LOOP_INTERVAL or 300)
self._lock = rdb.lock('celery:beat:task_lock')
self._lock_acquired = self._lock.acquire(blocking=False)
self.Entry.scheduler = self
示例11: reserve
def reserve(self, entry):
new_entry = Scheduler.reserve(self, entry)
# Need to story entry by name, because the entry may change
# in the mean time.
self._dirty.add(new_entry.name)
if self.should_flush():
self.logger.debug("Celerybeat: Writing schedule changes...")
self.flush()
return new_entry
示例12: reserve
def reserve(self, entry):
"""
This is called when a new instance of a task is scheduled to run. Hook
in here so we can avoid saving updates to tasks that have none.
"""
new_entry = Scheduler.reserve(self, entry)
# Add to a list of what has changed. Store by name since the entry
# itself may be a different instance by the time we get to it.
self._dirty.add(new_entry.name)
return new_entry
示例13: __init__
def __init__(self, *args, **kwargs):
if hasattr(current_app.conf, "CELERY_MONGODB_SCHEDULER_DB"):
db = current_app.conf.CELERY_MONGODB_SCHEDULER_DB
else:
db = "celery"
if hasattr(current_app.conf, "CELERY_MONGODB_SCHEDULER_URL"):
self._mongo = mongoengine.connect(db, host=current_app.conf.CELERY_MONGODB_SCHEDULER_URL)
get_logger(__name__).info("backend scheduler using %s/%s:%s",
current_app.conf.CELERY_MONGODB_SCHEDULER_URL,
db, self.Model._get_collection().name)
else:
self._mongo = mongoengine.connect(db)
get_logger(__name__).info("backend scheduler using %s/%s:%s",
"mongodb://localhost",
db, self.Model._get_collection().name)
self._schedule = {}
self._last_updated = None
Scheduler.__init__(self, *args, **kwargs)
self.max_interval = (kwargs.get('max_interval')
or self.app.conf.CELERYBEAT_MAX_LOOP_INTERVAL or 5)
示例14: maybe_due
def maybe_due(self, entry, publisher=None):
is_due, next_time_to_run = entry.is_due()
if not is_due:
return next_time_to_run
lock = self._lock(entry.name)
if not lock:
return next_time_to_run
try:
# Now that we have the lock, double-check the timestamps on the
# entry before executing it.
entry = self._schedule.sync(entry.name)
if entry is None:
return next_time_to_run
is_due, next_time_to_run = entry.is_due()
if not is_due:
return next_time_to_run
return Scheduler.maybe_due(self, entry, publisher)
finally:
self._unlock(lock)
示例15: cls
return cls(db_entry)
class DatabaseScheduler(Scheduler):
Entry = Entry
_last_timestamp = None
_schedule = None
_initial_read = False
def __init__(self, app, **kwargs):
<<<<<<< HEAD
print 'DBScheduler initiated'
=======
>>>>>>> eb2a33c4b2f857754113985e104210382f7b5a44
self._last_timestamp = self._get_latest_change()
Scheduler.__init__(self, app, **kwargs)
def _get_latest_change(self):
query = dbsession.query(DatabaseSchedulerEntry.date_changed)
query = query.order_by(DatabaseSchedulerEntry.date_changed.desc())
latest_entry_date = query.first()
return latest_entry_date
def setup_schedule(self):
self.install_default_entries(self.schedule)
self.update_from_dict(self.app.conf.CELERYBEAT_SCHEDULE)
def _all_as_schedule(self):
s = {}
query = dbsession.query(DatabaseSchedulerEntry)
query = query.filter_by(enabled=True)