本文整理汇总了Python中apscheduler.schedulers.background.BlockingScheduler类的典型用法代码示例。如果您正苦于以下问题:Python BlockingScheduler类的具体用法?Python BlockingScheduler怎么用?Python BlockingScheduler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BlockingScheduler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cli
def cli(ctx, helium_key, darksky_key, lat, lon, sensor, every):
"""Monitor weather for a lat/lon locaation.
This sample service shows how you can use an external weather
service to emit to a virtual sensor in the Helium platform.
\b
he-weather --every <seconds> <sensor> <lat> <lon>
The given virtual <sensor> is the id of a created Helium virtual
sensor.
The optional <seconds> parameter sets how often weather
information needs to get fetched and posted to Helium. If the
parameter is not provided a default (60 seconds)) is picked.
This will run the service based on the given lat/lon.
"""
client = Client(api_token=helium_key)
sensor = Sensor.find(client, sensor)
logging.basicConfig()
scheduler = BlockingScheduler()
scheduler.add_job(_process_weather, "interval",
seconds=every,
next_run_time=datetime.now(),
args=[darksky_key, lat, lon, sensor])
click.echo("Checking every {} seconds".format(every))
scheduler.start()
示例2: MonkeyHorde
class MonkeyHorde(object):
def __init__(self, config_file):
self.config_file = config_file
self.monkey_list = [
dict(class_name=ChaosMonkey),
dict(class_name=SecurityMonkey),
]
self.twitter = self.get_twitter_connector()
self.scheduler = BlockingScheduler()
for m in self.monkey_list:
m['class_name'](config_file, self.scheduler, self.twitter)
def unleash(self):
if self.twitter:
try:
self.twitter.PostUpdate("I unleashed the evil monkey horde!!!")
except Exception as e:
log.exception(e)
self.scheduler.start()
def get_twitter_connector(self):
try:
credentials = self.config_file.items("twitter")
except ConfigParser.NoSectionError:
return None
return twitter.Api(**dict(credentials))
示例3: cmd_start
def cmd_start(self):
from apscheduler.schedulers.background import BlockingScheduler
sched = BlockingScheduler()
with transaction.manager:
Scheduler.add_all_to_apscheduler(sched, DbSession, user=SYSTEM_UID,
begin_transaction=True)
sched.start()
sched.print_jobs()
示例4: month_task
def month_task(self):
def func():
self.dh.aum_total()
self.dh.debt_total()
scheduler = BlockingScheduler()
scheduler.add_job(func, 'cron', month='*/1', day='1', hour='5') # 每月一号五点运行
示例5: run
def run(self):
"""Run watcher"""
self.logger.info("Running watcher ...")
scheduler = BlockingScheduler()
scheduler.add_job(self.watching, 'interval', seconds=self.config["interval"])
try:
scheduler.start()
except (KeyboardInterrupt, SystemExit):
pass
示例6: half_year_task
def half_year_task(self):
def func():
month = datetime.datetime.now().month - 1
year = datetime.datetime.now().year
if month == 0:
month = 12
year = year - 1
half_year = month/6
self.dh.customer_value(year,half_year)
scheduler = BlockingScheduler()
scheduler.add_job(func, 'cron', month='7,12', day='2', hour='5') # 7月12月2号五点计算客户价值
示例7: MonkeyRunner
class MonkeyRunner(object):
def __init__(self, config_file):
self.config_file = config_file
self.monkey_list = [
dict(class_name=ChaosMonkey),
dict(class_name=JanitorMonkey),
dict(class_name=SecurityMonkey),
]
self.scheduler = BlockingScheduler()
for m in self.monkey_list:
m['class_name'](config_file, self.scheduler)
def start(self):
self.scheduler.start()
示例8: get_rescheduler
def get_rescheduler():
timer = BlockingScheduler()
time_spec = {
'seconds': cfg.CONF.scheduler.rescheduling_interval,
'timezone': aps_utils.astimezone('UTC')
}
timer.add_job(recover_delayed_executions,
trigger=IntervalTrigger(**time_spec),
max_instances=1,
misfire_grace_time=60,
next_run_time=date_utils.get_datetime_utc_now(),
replace_existing=True)
return timer
示例9: seasonly_task
def seasonly_task(self):
def func():
# 每个月计算前一个月的数据
month = datetime.datetime.now().month - 1
year = datetime.datetime.now().year
if month == 0:
month = 12
year = year-1
season = month/3
# 计算生命周期
self.dh.run_life_cycle(year,season)
scheduler = BlockingScheduler()
scheduler.add_job(func, 'cron', month='1,4,7,10', day='2', hour='2')
示例10: __init__
def __init__(self, config_file):
self.config_file = config_file
self.monkey_list = [
dict(class_name=ChaosMonkey),
dict(class_name=SecurityMonkey),
]
self.twitter = self.get_twitter_connector()
self.scheduler = BlockingScheduler()
for m in self.monkey_list:
m['class_name'](config_file, self.scheduler, self.twitter)
示例11: __init__
def __init__(self, local_timezone=None):
self._timezone = local_timezone
self._scheduler = BlockingScheduler(timezone=self._timezone)
self._jobs = {}
self._trigger_types = TIMER_TRIGGER_TYPES.keys()
self._trigger_watcher = TriggerWatcher(create_handler=self._handle_create_trigger,
update_handler=self._handle_update_trigger,
delete_handler=self._handle_delete_trigger,
trigger_types=self._trigger_types,
queue_suffix='timers')
self._trigger_dispatcher = TriggerDispatcher(LOG)
示例12: __init__
def __init__(self, local_timezone=None):
self._timezone = local_timezone
self._scheduler = BlockingScheduler(timezone=self._timezone)
self._jobs = {}
self._trigger_types = list(TIMER_TRIGGER_TYPES.keys())
self._trigger_watcher = TriggerWatcher(create_handler=self._handle_create_trigger,
update_handler=self._handle_update_trigger,
delete_handler=self._handle_delete_trigger,
trigger_types=self._trigger_types,
queue_suffix=self.__class__.__name__,
exclusive=True)
self._trigger_dispatcher = TriggerDispatcher(LOG)
示例13: ScheduledCheck
class ScheduledCheck(Check, metaclass=ABCMeta):
'''
An abstract base class for a check that runs based on
the Scheduler from apscheduler
Child classes need to implement the check method
'''
def __init__(self, queue=None, notify_on_exception=True, name=None, **kwargs):
'''
Create a new instance of this Check
The kwargs are handed over to apscheduler.blocking.BlockingScheduler.add_job
and decide when the checks are run. For example `trigger='cron', hour=8` will
run this check every day at 8 o'clock
'''
super().__init__(queue=queue, notify_on_exception=notify_on_exception, name=name)
self.scheduler = BlockingScheduler(
job_defaults={'misfire_grace_time': 5*60}
)
self.scheduler.add_job(self.wrapped_check, **kwargs)
def run(self):
self.scheduler.start()
def stop(self):
self.scheduler.shutdown()
self.log.info('Check %s stopped', self.__class__.__name__)
示例14: __init__
def __init__(self, queue=None, notify_on_exception=True, name=None, **kwargs):
'''
Create a new instance of this Check
The kwargs are handed over to apscheduler.blocking.BlockingScheduler.add_job
and decide when the checks are run. For example `trigger='cron', hour=8` will
run this check every day at 8 o'clock
'''
super().__init__(queue=queue, notify_on_exception=notify_on_exception, name=name)
self.scheduler = BlockingScheduler(
job_defaults={'misfire_grace_time': 5*60}
)
self.scheduler.add_job(self.wrapped_check, **kwargs)
示例15: __init__
def __init__(self):
KEY1 = 'UwVrGX4x2r+Pk7bf1aItja=='
self.token = '4ac1c0259b27f13dfb78c2959da3bf4e'
self.pc = prpcrypt(b(KEY1)) # 初始化密钥
self.info_log = get_logger('logs/info.log')
self.db = self.connect_db()
# 查找剩余需要爬取的疾病数量
self.max_len = self.db.disease.count_documents({ 'finished': 0 })
self.count = 0
print('Number of the lefting disease: {}'.format(self.max_len))
self.info_log.warning('Number of the lefting disease: {}'.format(self.max_len))
if self.max_len > 0:
print('Task started.')
print('-' * 50)
self.info_log.warning('Task started.....')
# 定时爬取
self.scheduler = BlockingScheduler()
self.scheduler.add_job(self.request_data, 'interval', id='main_schedule', seconds=120, args=[self])
self.scheduler.start()