本文整理汇总了Python中apscheduler.jobstores.base.ConflictingIdError方法的典型用法代码示例。如果您正苦于以下问题:Python base.ConflictingIdError方法的具体用法?Python base.ConflictingIdError怎么用?Python base.ConflictingIdError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apscheduler.jobstores.base
的用法示例。
在下文中一共展示了base.ConflictingIdError方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_job
# 需要导入模块: from apscheduler.jobstores import base [as 别名]
# 或者: from apscheduler.jobstores.base import ConflictingIdError [as 别名]
def add_job(self, job):
insert = self.jobs_t.insert().values(**{
'id': job.id,
'next_run_time': datetime_to_utc_timestamp(job.next_run_time),
'job_state': pickle.dumps(job.__getstate__(),
self.pickle_protocol),
'service_id': self.service_id,
'tag': jsonutils.dumps(self.tag)
})
try:
self.engine.execute(insert)
except IntegrityError:
raise ConflictingIdError(job.id)
示例2: add_date_job
# 需要导入模块: from apscheduler.jobstores import base [as 别名]
# 或者: from apscheduler.jobstores.base import ConflictingIdError [as 别名]
def add_date_job(datetime_str, job_id, task, args_):
global g_main_scheduler
run_time = datetime.strptime(datetime_str, '%Y-%m-%dT%H:%M:%S.%fZ')
run_time = run_time - timedelta(minutes=30)
try:
g_main_scheduler.add_job(task, args=args_, id=job_id, name=task.__qualname__, next_run_time=run_time, misfire_grace_time=3600*2)
except ConflictingIdError:
g_main_scheduler.modify_job(job_id, func=task, args=args_, name=task.__qualname__, next_run_time=run_time)
log_jobs()
示例3: add_job
# 需要导入模块: from apscheduler.jobstores import base [as 别名]
# 或者: from apscheduler.jobstores.base import ConflictingIdError [as 别名]
def add_job(self, job):
self._ensure_paths()
node_path = os.path.join(self.path, str(job.id))
value = {
'next_run_time': datetime_to_utc_timestamp(job.next_run_time),
'job_state': job.__getstate__()
}
data = pickle.dumps(value, self.pickle_protocol)
try:
self.client.create(node_path, value=data)
except NodeExistsError:
raise ConflictingIdError(job.id)
示例4: add_job
# 需要导入模块: from apscheduler.jobstores import base [as 别名]
# 或者: from apscheduler.jobstores.base import ConflictingIdError [as 别名]
def add_job(self, job):
if self.redis.hexists(self.jobs_key, job.id):
raise ConflictingIdError(job.id)
with self.redis.pipeline() as pipe:
pipe.multi()
pipe.hset(self.jobs_key, job.id, pickle.dumps(job.__getstate__(),
self.pickle_protocol))
if job.next_run_time:
pipe.zadd(self.run_times_key, datetime_to_utc_timestamp(job.next_run_time), job.id)
pipe.execute()
示例5: add_job
# 需要导入模块: from apscheduler.jobstores import base [as 别名]
# 或者: from apscheduler.jobstores.base import ConflictingIdError [as 别名]
def add_job(self, job):
insert = self.jobs_t.insert().values(**{
'id': job.id,
'next_run_time': datetime_to_utc_timestamp(job.next_run_time),
'job_state': pickle.dumps(job.__getstate__(), self.pickle_protocol)
})
try:
self.engine.execute(insert)
except IntegrityError:
raise ConflictingIdError(job.id)
示例6: add_job
# 需要导入模块: from apscheduler.jobstores import base [as 别名]
# 或者: from apscheduler.jobstores.base import ConflictingIdError [as 别名]
def add_job(self, job):
if job.id in self._jobs_index:
raise ConflictingIdError(job.id)
timestamp = datetime_to_utc_timestamp(job.next_run_time)
index = self._get_job_index(timestamp, job.id)
self._jobs.insert(index, (job, timestamp))
self._jobs_index[job.id] = (job, timestamp)
示例7: add_job
# 需要导入模块: from apscheduler.jobstores import base [as 别名]
# 或者: from apscheduler.jobstores.base import ConflictingIdError [as 别名]
def add_job(self, job):
try:
self.collection.insert({
'_id': job.id,
'next_run_time': datetime_to_utc_timestamp(job.next_run_time),
'job_state': Binary(pickle.dumps(job.__getstate__(), self.pickle_protocol))
})
except DuplicateKeyError:
raise ConflictingIdError(job.id)
示例8: add_job
# 需要导入模块: from apscheduler.jobstores import base [as 别名]
# 或者: from apscheduler.jobstores.base import ConflictingIdError [as 别名]
def add_job(self, job):
if self.redis.hexists(self.jobs_key, job.id):
raise ConflictingIdError(job.id)
with self.redis.pipeline() as pipe:
pipe.multi()
pipe.hset(self.jobs_key, job.id, pickle.dumps(job.__getstate__(),
self.pickle_protocol))
if job.next_run_time:
pipe.zadd(self.run_times_key,
{job.id: datetime_to_utc_timestamp(job.next_run_time)})
pipe.execute()
示例9: add_scheduled_commands
# 需要导入模块: from apscheduler.jobstores import base [as 别名]
# 或者: from apscheduler.jobstores.base import ConflictingIdError [as 别名]
def add_scheduled_commands(
commands: Union[ScheduledCommand, List[ScheduledCommand]], *,
job_id: str, ctx: Dict[str, Any],
trigger: str,
replace_existing: bool = False,
misfire_grace_time: int = 360,
apscheduler_kwargs: Dict[str, Any] = None,
**trigger_args) -> Job:
"""
Add commands to scheduler for scheduled execution.
:param commands: commands to add, can be a single ScheduledCommand
:param job_id: job id, using of make_job_id() is recommended
:param ctx: context dict
:param trigger: same as APScheduler
:param replace_existing: same as APScheduler
:param misfire_grace_time: same as APScheduler
:param apscheduler_kwargs: other APScheduler keyword args
:param trigger_args: same as APScheduler
"""
commands = [commands] \
if isinstance(commands, ScheduledCommand) else commands
try:
return await aio.run_sync_func(
nb.scheduler.add_job,
_scheduled_commands_callback,
id=job_id,
trigger=trigger, **trigger_args,
kwargs={'ctx': ctx, 'commands': commands},
replace_existing=replace_existing,
misfire_grace_time=misfire_grace_time,
**(apscheduler_kwargs or {}))
except ConflictingIdError:
raise JobIdConflictError(job_id)
示例10: add_job
# 需要导入模块: from apscheduler.jobstores import base [as 别名]
# 或者: from apscheduler.jobstores.base import ConflictingIdError [as 别名]
def add_job():
"""Adds a new job."""
data = request.get_json(force=True)
try:
job = current_app.apscheduler.add_job(**data)
return jsonify(job)
except ConflictingIdError:
return jsonify(dict(error_message='Job %s already exists.' % data.get('id')), status=409)
except Exception as e:
return jsonify(dict(error_message=str(e)), status=500)
示例11: _real_add_job
# 需要导入模块: from apscheduler.jobstores import base [as 别名]
# 或者: from apscheduler.jobstores.base import ConflictingIdError [as 别名]
def _real_add_job(self, job, jobstore_alias, replace_existing):
"""
:param Job job: the job to add
:param bool replace_existing: ``True`` to use update_job() in case the job already exists
in the store
"""
# Fill in undefined values with defaults
replacements = {}
for key, value in six.iteritems(self._job_defaults):
if not hasattr(job, key):
replacements[key] = value
# Calculate the next run time if there is none defined
if not hasattr(job, 'next_run_time'):
now = datetime.now(self.timezone)
replacements['next_run_time'] = job.trigger.get_next_fire_time(None, now)
# Apply any replacements
job._modify(**replacements)
# Add the job to the given job store
store = self._lookup_jobstore(jobstore_alias)
try:
store.add_job(job)
except ConflictingIdError:
if replace_existing:
store.update_job(job)
else:
raise
# Mark the job as no longer pending
job._jobstore_alias = jobstore_alias
# Notify listeners that a new job has been added
event = JobEvent(EVENT_JOB_ADDED, job.id, jobstore_alias)
self._dispatch_event(event)
self._logger.info('Added job "%s" to job store "%s"', job.name, jobstore_alias)
# Notify the scheduler about the new job
if self.state == STATE_RUNNING:
self.wakeup()