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


Python base.JobLookupError方法代碼示例

本文整理匯總了Python中apscheduler.jobstores.base.JobLookupError方法的典型用法代碼示例。如果您正苦於以下問題:Python base.JobLookupError方法的具體用法?Python base.JobLookupError怎麽用?Python base.JobLookupError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在apscheduler.jobstores.base的用法示例。


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

示例1: _lookup_job

# 需要導入模塊: from apscheduler.jobstores import base [as 別名]
# 或者: from apscheduler.jobstores.base import JobLookupError [as 別名]
def _lookup_job(self, job_id, jobstore_alias):
        """
        Finds a job by its ID.

        :type job_id: str
        :param str jobstore_alias: alias of a job store to look in
        :return tuple[Job, str]: a tuple of job, jobstore alias (jobstore alias is None in case of
            a pending job)
        :raises JobLookupError: if no job by the given ID is found.

        """
        if self.state == STATE_STOPPED:
            # Check if the job is among the pending jobs
            for job, alias, replace_existing in self._pending_jobs:
                if job.id == job_id:
                    return job, None
        else:
            # Look in all job stores
            for alias, store in six.iteritems(self._jobstores):
                if jobstore_alias in (None, alias):
                    job = store.lookup_job(job_id)
                    if job is not None:
                        return job, alias

        raise JobLookupError(job_id) 
開發者ID:morpheus65535,項目名稱:bazarr,代碼行數:27,代碼來源:base.py

示例2: update_job

# 需要導入模塊: from apscheduler.jobstores import base [as 別名]
# 或者: from apscheduler.jobstores.base import JobLookupError [as 別名]
def update_job(self, job):
        old_job, old_timestamp = self._jobs_index.get(job.id, (None, None))
        if old_job is None:
            raise JobLookupError(job.id)

        # If the next run time has not changed, simply replace the job in its present index.
        # Otherwise, reinsert the job to the list to preserve the ordering.
        old_index = self._get_job_index(old_timestamp, old_job.id)
        new_timestamp = datetime_to_utc_timestamp(job.next_run_time)
        if old_timestamp == new_timestamp:
            self._jobs[old_index] = (job, new_timestamp)
        else:
            del self._jobs[old_index]
            new_index = self._get_job_index(new_timestamp, job.id)
            self._jobs.insert(new_index, (job, new_timestamp))

        self._jobs_index[old_job.id] = (job, new_timestamp) 
開發者ID:morpheus65535,項目名稱:bazarr,代碼行數:19,代碼來源:memory.py

示例3: _remove_a_scheduled_job

# 需要導入模塊: from apscheduler.jobstores import base [as 別名]
# 或者: from apscheduler.jobstores.base import JobLookupError [as 別名]
def _remove_a_scheduled_job(self, event, *args, **kwargs):
        try:
            scheduler_label = kwargs.get("scheduler_label")  # text
            log.info(u"scheduler_label: %s", scheduler_label)
            validate_fields(["scheduler_label"], kwargs)

            rc = ResultPayload(SECTION_SCHEDULER, **kwargs)

            scheduler = ResilientScheduler.get_scheduler()

            try:
                scheduler.remove_job(scheduler_label)
                log.info(u"Rule '{}' deleted".format(scheduler_label))

                yield StatusMessage("Scheduled rule removed")
                result = rc.done(True, None)
            except JobLookupError:
                yield StatusMessage("Scheduled rule not found")
                result = rc.done(False, None)

            yield FunctionResult(result)
        except Exception:
            yield FunctionError() 
開發者ID:ibmresilient,項目名稱:resilient-community-apps,代碼行數:25,代碼來源:remove_a_scheduled_rule.py

示例4: register_routes

# 需要導入模塊: from apscheduler.jobstores import base [as 別名]
# 或者: from apscheduler.jobstores.base import JobLookupError [as 別名]
def register_routes(self):
        @self.route("/delete_job/<job_id>", methods=["POST"])
        def delete_job(job_id):
            if self.scheduler.get_job(job_id):
                self.scheduler.remove_job(job_id)
            return jsonify(True)

        @self.route("/next_runtime/<task_id>")
        def next_runtime(task_id):
            job = self.scheduler.get_job(task_id)
            if job and job.next_run_time:
                return jsonify(job.next_run_time.strftime("%Y-%m-%d %H:%M:%S"))
            return jsonify("Not Scheduled")

        @self.route("/schedule", methods=["POST"])
        def schedule():
            if request.json["mode"] in ("resume", "schedule"):
                result = self.schedule_task(request.json["task"])
                if not result:
                    return jsonify({"alert": "Cannot schedule in the past."})
                else:
                    return jsonify({"response": "Task resumed.", "active": True})
            else:
                try:
                    self.scheduler.pause_job(request.json["task"]["id"])
                    return jsonify({"response": "Task paused."})
                except JobLookupError:
                    return jsonify({"alert": "There is no such job scheduled."})

        @self.route("/time_left/<task_id>")
        def time_left(task_id):
            job = self.scheduler.get_job(task_id)
            if job and job.next_run_time:
                delta = job.next_run_time.replace(tzinfo=None) - datetime.now()
                hours, remainder = divmod(delta.seconds, 3600)
                minutes, seconds = divmod(remainder, 60)
                days = f"{delta.days} days, " if delta.days else ""
                return jsonify(f"{days}{hours}h:{minutes}m:{seconds}s")
            return jsonify("Not Scheduled") 
開發者ID:eNMS-automation,項目名稱:eNMS,代碼行數:41,代碼來源:scheduler.py

示例5: lookup_job

# 需要導入模塊: from apscheduler.jobstores import base [as 別名]
# 或者: from apscheduler.jobstores.base import JobLookupError [as 別名]
def lookup_job(self, job_id):
        job = Executor.query.get(job_id)
        if not job:
            raise JobLookupError("job with id %s not found" % job_id)
        else:
            return self._reconstitute_job(job.job_state) if job.job_state else None 
開發者ID:BBVA,項目名稱:chaos-monkey-engine,代碼行數:8,代碼來源:cme_sqlalchemy_store.py

示例6: remove_job

# 需要導入模塊: from apscheduler.jobstores import base [as 別名]
# 或者: from apscheduler.jobstores.base import JobLookupError [as 別名]
def remove_job(self, job_id):
        """
        Instead of deleting a job when its executed or it has failed, check it as executed.

        TODO: delete the executor and save to a historic table the executed attacks with its
        logs and results.
        """
        job_model = Executor.query.get(job_id)
        if job_model is None:
            raise JobLookupError(job_id)

        job_model.executed = True
        db.session.commit()

        self._check_plan_executed(job_id) 
開發者ID:BBVA,項目名稱:chaos-monkey-engine,代碼行數:17,代碼來源:cme_sqlalchemy_store.py

示例7: real_remove_job

# 需要導入模塊: from apscheduler.jobstores import base [as 別名]
# 或者: from apscheduler.jobstores.base import JobLookupError [as 別名]
def real_remove_job(self, job_id):
        self.log.debug('real remove job %s', job_id)
        job_model = Executor.query.get(job_id)
        if job_model is None:
            raise JobLookupError(job_id)

        db.session.delete(job_model)
        db.session.commit() 
開發者ID:BBVA,項目名稱:chaos-monkey-engine,代碼行數:10,代碼來源:cme_sqlalchemy_store.py

示例8: stop_job

# 需要導入模塊: from apscheduler.jobstores import base [as 別名]
# 或者: from apscheduler.jobstores.base import JobLookupError [as 別名]
def stop_job(resource_id):
    LOGGER.info('Stopping job for resource=%d' % resource_id)

    # Try to remove job from scheduler
    try:
        scheduler.remove_job(str(resource_id))
    except JobLookupError:
        pass 
開發者ID:geopython,項目名稱:GeoHealthCheck,代碼行數:10,代碼來源:scheduler.py

示例9: delete_job_by_id

# 需要導入模塊: from apscheduler.jobstores import base [as 別名]
# 或者: from apscheduler.jobstores.base import JobLookupError [as 別名]
def delete_job_by_id(self, job_id):
        print("removing job id {} form the scheduler".format(job_id))
        try:
            self.scheduler.remove_job(str(job_id))
        except JobLookupError:
            print("Job id {} was already deleted".format(job_id)) 
開發者ID:Sispheor,項目名稱:piclodio3,代碼行數:8,代碼來源:scheduler_manager.py

示例10: get_job

# 需要導入模塊: from apscheduler.jobstores import base [as 別名]
# 或者: from apscheduler.jobstores.base import JobLookupError [as 別名]
def get_job(scheduler, job_id):
    """Get a job given a job_id, if none, return None"""
    try:
        return scheduler.get_job(job_id)
    except base.JobLookupError:
        return None 
開發者ID:Morgan-Stanley,項目名稱:treadmill,代碼行數:8,代碼來源:__init__.py

示例11: get_job

# 需要導入模塊: from apscheduler.jobstores import base [as 別名]
# 或者: from apscheduler.jobstores.base import JobLookupError [as 別名]
def get_job(self, job_id, jobstore=None):
        """
        Returns the Job that matches the given ``job_id``.

        :param str|unicode job_id: the identifier of the job
        :param str|unicode jobstore: alias of the job store that most likely contains the job
        :return: the Job by the given ID, or ``None`` if it wasn't found
        :rtype: Job

        """
        with self._jobstores_lock:
            try:
                return self._lookup_job(job_id, jobstore)[0]
            except JobLookupError:
                return 
開發者ID:morpheus65535,項目名稱:bazarr,代碼行數:17,代碼來源:base.py

示例12: remove_job

# 需要導入模塊: from apscheduler.jobstores import base [as 別名]
# 或者: from apscheduler.jobstores.base import JobLookupError [as 別名]
def remove_job(self, job_id, jobstore=None):
        """
        Removes a job, preventing it from being run any more.

        :param str|unicode job_id: the identifier of the job
        :param str|unicode jobstore: alias of the job store that contains the job
        :raises JobLookupError: if the job was not found

        """
        jobstore_alias = None
        with self._jobstores_lock:
            if self.state == STATE_STOPPED:
                # Check if the job is among the pending jobs
                if self.state == STATE_STOPPED:
                    for i, (job, alias, replace_existing) in enumerate(self._pending_jobs):
                        if job.id == job_id and jobstore in (None, alias):
                            del self._pending_jobs[i]
                            jobstore_alias = alias
                            break
            else:
                # Otherwise, try to remove it from each store until it succeeds or we run out of
                # stores to check
                for alias, store in six.iteritems(self._jobstores):
                    if jobstore in (None, alias):
                        try:
                            store.remove_job(job_id)
                            jobstore_alias = alias
                            break
                        except JobLookupError:
                            continue

        if jobstore_alias is None:
            raise JobLookupError(job_id)

        # Notify listeners that a job has been removed
        event = JobEvent(EVENT_JOB_REMOVED, job_id, jobstore_alias)
        self._dispatch_event(event)

        self._logger.info('Removed job %s', job_id) 
開發者ID:morpheus65535,項目名稱:bazarr,代碼行數:41,代碼來源:base.py

示例13: update_job

# 需要導入模塊: from apscheduler.jobstores import base [as 別名]
# 或者: from apscheduler.jobstores.base import JobLookupError [as 別名]
def update_job(self, job):
        self._ensure_paths()
        node_path = os.path.join(self.path,  str(job.id))
        changes = {
            'next_run_time': datetime_to_utc_timestamp(job.next_run_time),
            'job_state': job.__getstate__()
        }
        data = pickle.dumps(changes, self.pickle_protocol)
        try:
            self.client.set(node_path, value=data)
        except NoNodeError:
            raise JobLookupError(job.id) 
開發者ID:morpheus65535,項目名稱:bazarr,代碼行數:14,代碼來源:zookeeper.py

示例14: remove_job

# 需要導入模塊: from apscheduler.jobstores import base [as 別名]
# 或者: from apscheduler.jobstores.base import JobLookupError [as 別名]
def remove_job(self, job_id):
        self._ensure_paths()
        node_path = os.path.join(self.path,  str(job_id))
        try:
            self.client.delete(node_path)
        except NoNodeError:
            raise JobLookupError(job_id) 
開發者ID:morpheus65535,項目名稱:bazarr,代碼行數:9,代碼來源:zookeeper.py

示例15: remove_job

# 需要導入模塊: from apscheduler.jobstores import base [as 別名]
# 或者: from apscheduler.jobstores.base import JobLookupError [as 別名]
def remove_job(self, job_id):
        if not self.redis.hexists(self.jobs_key, job_id):
            raise JobLookupError(job_id)

        with self.redis.pipeline() as pipe:
            pipe.hdel(self.jobs_key, job_id)
            pipe.zrem(self.run_times_key, job_id)
            pipe.execute() 
開發者ID:morpheus65535,項目名稱:bazarr,代碼行數:10,代碼來源:redis.py


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