本文整理汇总了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)
示例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)
示例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()
示例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")
示例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
示例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)
示例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()
示例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
示例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))
示例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
示例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
示例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)
示例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)
示例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)
示例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()