当前位置: 首页>>代码示例>>Python>>正文


Python background.BlockingScheduler类代码示例

本文整理汇总了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()
开发者ID:helium,项目名称:api-examples,代码行数:30,代码来源:he-weather.py

示例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))
开发者ID:hacktm,项目名称:Open-source-ChaosMonkeys,代码行数:27,代码来源:monkeyhorde.py

示例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()
开发者ID:dmdm,项目名称:Parenchym,代码行数:8,代码来源:scheduler.py

示例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') # 每月一号五点运行
开发者ID:summer-apple,项目名称:spark,代码行数:9,代码来源:tasks.py

示例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
开发者ID:cuongnb14,项目名称:watcher-elasticsearch,代码行数:9,代码来源:nbc_watcher.py

示例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号五点计算客户价值
开发者ID:summer-apple,项目名称:spark,代码行数:14,代码来源:tasks.py

示例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()
开发者ID:ioanaverebi,项目名称:pySimians,代码行数:15,代码来源:monkeyrunner.py

示例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
开发者ID:lyandut,项目名称:st2,代码行数:16,代码来源:scheduler.py

示例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')
开发者ID:summer-apple,项目名称:spark,代码行数:16,代码来源:tasks.py

示例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)
开发者ID:hacktm,项目名称:Open-source-ChaosMonkeys,代码行数:10,代码来源:monkeyhorde.py

示例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)
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:11,代码来源:base.py

示例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)
开发者ID:lyandut,项目名称:st2,代码行数:12,代码来源:base.py

示例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__)
开发者ID:fact-project,项目名称:pycustos,代码行数:27,代码来源:__init__.py

示例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)
开发者ID:fact-project,项目名称:pycustos,代码行数:13,代码来源:__init__.py

示例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()
开发者ID:Andyliwr,项目名称:PythonStudyLoad,代码行数:19,代码来源:xiaochengxu.py


注:本文中的apscheduler.schedulers.background.BlockingScheduler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。