當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。