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


Python job.Job類代碼示例

本文整理匯總了Python中apscheduler.job.Job的典型用法代碼示例。如果您正苦於以下問題:Python Job類的具體用法?Python Job怎麽用?Python Job使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: _reconstitute_job

    def _reconstitute_job(self, job_state):
        schedule = job_state['schedule']
        schedule.pop('coalesce', None)
        next_run_time = job_state['next_run_time']

        if next_run_time == 1:
            # This is hacky. We need to subtract more than value of misfire_grace_time
            # so that the job will be missed right after loading it for the first time
            # after doing fresh install instead of being executed.
            next_run_time = int(time.time() - 1200)

        job = Job(
            id=job_state['id'],
            func="__main__:job",
            trigger=CronTrigger(**schedule),
            name=job_state['name'],
            args=[job_state['task']] + job_state['args'],
            scheduler=self._scheduler,
            executor='default',
            next_run_time=utc_timestamp_to_datetime(next_run_time),
            kwargs={
                'id': job_state['id'],
                'name': job_state['name'],
                'hidden': job_state.get('hidden', False),
                'protected': job_state.get('protected', False)
            }
        )

        job.coalesce = True
        job.max_instances = 1
        job.misfire_grace_time = 600
        job._jobstore_alias = self._alias
        return job
開發者ID:erinix,項目名稱:middleware,代碼行數:33,代碼來源:store.py

示例2: _update_scheduler_status

def _update_scheduler_status(scheduler, config):
    now = datetime.now()
    working_hours = parse_working_hours(config)
    jobs = scheduler.get_jobs()
    work = False
    for start, end in working_hours:
        if start <= (now.hour * 60 + now.minute) <= end:
            work = True
    if not work:
        for j in jobs:
            if j.name == 'partial' and \
               j.func.func.__name__ in excluded_job_names:
                continue
            j.pause()
    else:
        # slack post message limit
        for job_id, times_ in g.items():
            if times_ > config.max_alert - 1:
                job = Job(scheduler, job_id)
                job.pause()
                stoped[job_id] = (job, now)
                g[job_id] = 0

        for job_id in list(stoped):
            job, time_ = stoped[job_id]
            if time_ + timedelta(minutes=config.pause_time) <= now:
                job.resume()
                del stoped[job_id]
        for j in jobs:
            if j.name == 'partial' and \
               j.func.func.__name__ in excluded_job_names:
                continue
            if j.id not in stoped:
                j.resume()
開發者ID:dongweiming,項目名稱:slack-alert,代碼行數:34,代碼來源:slack_alert.py

示例3: _reconstitute_job

    def _reconstitute_job(self, job_state):
        schedule = job_state['schedule']
        schedule.pop('coalesce', None)
        job = Job(
            id=job_state['id'],
            func="__main__:job",
            trigger=CronTrigger(**schedule),
            name=job_state['name'],
            args=[job_state['task']] + job_state['args'],
            scheduler=self._scheduler,
            executor='default',
            next_run_time=utc_timestamp_to_datetime(job_state['next_run_time']),
            kwargs={
                'id': job_state['id'],
                'name': job_state['name'],
                'hidden': job_state.get('hidden', False),
                'protected': job_state.get('protected', False)
            }
        )

        job.coalesce = True
        job.max_instances = 1
        job.misfire_grace_time = 0
        job._jobstore_alias = self._alias
        return job
開發者ID:freenas,項目名稱:middleware,代碼行數:25,代碼來源:store.py

示例4: __init__

 def __init__(self, *args, **kwargs):
     if len(args) > 1 and hasattr(args[1], '__call__') or 'func' in kwargs:
         models.Model.__init__(self)
         Job.__init__(self, *args, **kwargs)
     else:
         models.Model.__init__(self, *args, **kwargs)
         self.instances = 0
         self._lock = Lock()
         self.func = ref_to_obj(self.func_ref)
開發者ID:BusyJay,項目名稱:sokoban,代碼行數:9,代碼來源:models.py

示例5: add_job

 def add_job(self, key, jobname, trigger, func, args, kwargs, jobstore='default',
             **options): 
     job = Job(trigger, func, args or [], kwargs or {}, 
                 options.pop('misfire_grace_time', self.misfire_grace_time),
                 options.pop('coalesce', self.coalesce), name=jobname,  **options)
     job.key = key
     
     if not self.running:
         self._pending_jobs.append((job, jobstore))
     else:
         self._real_add_job(job, jobstore, True)
     return job
開發者ID:ganji-apollo,項目名稱:ControlTower,代碼行數:12,代碼來源:apolloscheduler.py

示例6: _reconstitute_job

 def _reconstitute_job(self, job_state):
     job_state = pickle.loads(job_state)
     job = Job.__new__(Job)
     job.__setstate__(job_state)
     job._scheduler = self._scheduler
     job._jobstore_alias = self._alias
     return job
開發者ID:cychenyin,項目名稱:windmill,代碼行數:7,代碼來源:mongodb.py

示例7: init

    def init(self):
        tz = self.store.timezone
        trigger = IntervalTrigger({}, minutes=5, timezone=tz)
        url     = 'http://t.cn'
        now = datetime.now(tz)

        self.job1 = Job(1, trigger, url)
        self.job1.compute_next_run_time(now)
        self.job2 = Job(2, trigger, url)
        self.job2.compute_next_run_time(now)

        self.store.add_job(self.job1)
        self.store.add_job(self.job2)


        self.now = now
        self.url = url
        self.trigger = trigger
開發者ID:reedboat,項目名稱:dcron,代碼行數:18,代碼來源:tests.py

示例8: load_jobs

    def load_jobs(self):
        jobs = []
        for job_dict in itervalues(self.store):
            try:
                job = Job.__new__(Job)
                job.__setstate__(job_dict)
                jobs.append(job)
            except Exception:
                job_name = job_dict.get('name', '(unknown)')
                logger.exception('Unable to restore job "%s"', job_name)

        self.jobs = jobs
開發者ID:Amelsfort,項目名稱:CouchPotatoServer,代碼行數:12,代碼來源:shelve_store.py

示例9: load_jobs

 def load_jobs(self):
     jobs = []
     for row in self.engine.execute(select([self.jobs_t])):
         try:
             job = Job.__new__(Job)
             job_dict = dict(row.items())
             job.__setstate__(job_dict)
             jobs.append(job)
         except Exception:
             job_name = job_dict.get("name", "(unknown)")
             logger.exception('Unable to restore job "%s"', job_name)
     self.jobs = jobs
開發者ID:roontoon,項目名稱:headphones,代碼行數:12,代碼來源:sqlalchemy_store.py

示例10: _reconstitute_job

 def _reconstitute_job(self, row):
     '''
         code gen by shell cmd: cat a | awk -F '=' '{print $1}' | cut -c5- | awk '{ print "job."$1" = row."$1}'
         what in file a is the wm_jobs_t create statement which can be found in the current source code file
     '''
             
     conf = JobConf()
     conf.id = row.id
     conf.cmd = row.cmd
     conf.cron_str = row.cron_str
     conf.name = row.name
     conf.desc = row.desc
     conf.mails = row.mails
     conf.phones = row.phones
     conf.team = row.team
     conf.owner = row.owner
     conf.hosts = row.hosts
     conf.host_strategy = row.host_strategy
     conf.restore_strategy = row.restore_strategy
     conf.retry_strategy = row.retry_strategy
     conf.error_strategy = row.error_strategy
     conf.exist_strategy = row.exist_strategy
     conf.running_timeout_s = row.running_timeout_s
     conf.status = row.status
     conf.modify_time = row.modify_time
     conf.modify_user = row.modify_user
     conf.create_time = row.create_time
     conf.create_user = row.create_user
     conf.start_date = row.start_date
     conf.end_date = row.end_date
     conf.oupput_match_reg = row.oupput_match_reg 
     conf.next_run_time = row.next_run_time 
     
     job = Job.__new__(Job)
     job.conf = conf
     job.id = job.conf.id
     job._scheduler = self._scheduler
     job._jobstore_alias = self._alias
     job.trigger = self._create_trigger_by_conf(job) 
     t = apscheduler.util.local_timestamp_to_datetime(conf.next_run_time) if conf.next_run_time > 0 else None
     t = apscheduler.util.convert_to_ware_datetime(t, get_localzone(), 'conf.next_run_time' )
     state = {
          'version': 1,
          'conf': conf, 
          'id': conf.id, 
          'name': conf.name, 
          'next_run_time': t, 
     }
     
     job.__setstate__(state)
     
     return job
開發者ID:cychenyin,項目名稱:windmill,代碼行數:52,代碼來源:mysqlstore.py

示例11: load_jobs

 def load_jobs(self):
     jobs = []
     for row in self.engine.execute(self.jobs_t.select()):
         try:
             job = Job.__new__(Job)
             job_dict = dict(row.items())
             job.__setstate__(job_dict)
             jobs.append(job)
         except Exception as e:
             print e
             traceback.print_exc(e)
             job_name = job_dict.get('name', '(unknown)')
             logger.exception('Unable to restore job "%s"', job_name)
     self.jobs = jobs
     return jobs
開發者ID:reedboat,項目名稱:dcron,代碼行數:15,代碼來源:sqlalchemy_store.py

示例12: load_jobs

 def load_jobs(self):
     jobs = []
     for job_dict in self.collection.find():
         try:
             job = Job.__new__(Job)
             job_dict['id'] = job_dict.pop('_id')
             job_dict['trigger'] = pickle.loads(job_dict['trigger'])
             job_dict['args'] = pickle.loads(job_dict['args'])
             job_dict['kwargs'] = pickle.loads(job_dict['kwargs'])
             job.__setstate__(job_dict)
             jobs.append(job)
         except Exception:
             job_name = job_dict.get('name', '(unknown)')
             logger.exception('Unable to restore job "%s"', job_name)
     self.jobs = jobs
開發者ID:entone,項目名稱:GeriCare,代碼行數:15,代碼來源:mongodb_store.py

示例13: get_job

    def get_job(self, id):
        select = self.jobs_t.select().where(self.jobs_t.c.id == id)
        try:
            row = self.engine.execute(select).fetchone()
        except Exception as e:
            #todo
            logger.exception(e)

        if row:
            try:
                job = Job.__new__(Job)
                job_dict = dict(row.items())
                job.__setstate__(job_dict)
                return job
            except Exception:
                job_name = job_dict.get('name', 'unknown')
                logger.exception("Unable to restore job '%s'", job_name)

        return None
開發者ID:reedboat,項目名稱:dcron,代碼行數:19,代碼來源:sqlalchemy_store.py

示例14: pop

 def pop(self, now):
     item = self.redis.rpop(self.key)
     if item is None:
         return 0, '', None
     try:
         job_id, change_type, job_str = item.split('||')
         job_id = int(job_id)
         if job_str == 'None':
             job = None
         else:
             job_state = pickle.loads(job_str)
             job = Job.__new__(Job)
             job.__setstate__(job_state)
             job.compute_next_run_time(now)
         return job_id, change_type, job
     except:
         logger=logging.getLogger('cron.backend')
         logger.exception('sync item invalid')
         return 0, ''
開發者ID:reedboat,項目名稱:dcron,代碼行數:19,代碼來源:jobstore.py

示例15: load_jobs

	def load_jobs(self):
		#continue standart execution
		jobs = []
		for job_dict in self.collection.find({'crecord_type': 'schedule'}):
			try:
				job = Job.__new__(Job)
				
				if job_dict['aaa_owner'] != 'root':
					if job_dict['kwargs']['task'] != 'task_reporting':
						raise ValueError("User %s isn\'t allow to run task %s" % (job_dict['aaa_owner'],job_dict['kwargs']['task']))
				
				#keep memory of id
				job_dict_id = job_dict['_id']
				
				job_dict['id'] = job_dict.pop('_id')
				
				if job_dict.has_key('runs'):
					job_dict['runs'] = job_dict['runs']
				else:
					job_dict['runs'] = 0
				
				job_dict['coalesce'] = False
				
				#try to get interval
				try:
					if job_dict['interval'] != None:
						job_dict['trigger'] = IntervalTrigger(timedelta(**job_dict['interval']))
				except Exception, err:
					pass
				
				#try to get simple
				try:
					if job_dict['date'] != None:
						job_dict['trigger'] = SimpleTrigger( datetime(*job_dict['date']))
				except Exception, err:
					pass
				
				#try to get crontab
				try:
					if job_dict['cron'] != None:
						job_dict['trigger'] = CronTrigger(**job_dict['cron'])
				except Exception, err:
					pass
開發者ID:Httqm,項目名稱:canopsis,代碼行數:43,代碼來源:cmongodbjobstore.py


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