当前位置: 首页>>代码示例>>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;未经允许,请勿转载。