You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
397 lines
15 KiB
Python
397 lines
15 KiB
Python
"""
|
|
This type stub file was generated by pyright.
|
|
"""
|
|
|
|
import sys
|
|
from abc import ABCMeta, abstractmethod
|
|
|
|
STATE_STOPPED = ...
|
|
STATE_RUNNING = ...
|
|
STATE_PAUSED = ...
|
|
class BaseScheduler(metaclass=ABCMeta):
|
|
"""
|
|
Abstract base class for all schedulers.
|
|
|
|
Takes the following keyword arguments:
|
|
|
|
:param str|logging.Logger logger: logger to use for the scheduler's logging (defaults to
|
|
apscheduler.scheduler)
|
|
:param str|datetime.tzinfo timezone: the default time zone (defaults to the local timezone)
|
|
:param int|float jobstore_retry_interval: the minimum number of seconds to wait between
|
|
retries in the scheduler's main loop if the job store raises an exception when getting
|
|
the list of due jobs
|
|
:param dict job_defaults: default values for newly added jobs
|
|
:param dict jobstores: a dictionary of job store alias -> job store instance or configuration
|
|
dict
|
|
:param dict executors: a dictionary of executor alias -> executor instance or configuration
|
|
dict
|
|
|
|
:ivar int state: current running state of the scheduler (one of the following constants from
|
|
``apscheduler.schedulers.base``: ``STATE_STOPPED``, ``STATE_RUNNING``, ``STATE_PAUSED``)
|
|
|
|
.. seealso:: :ref:`scheduler-config`
|
|
"""
|
|
if (3, 8) <= sys.version_info < (3, 10):
|
|
_trigger_plugins = ...
|
|
_executor_plugins = ...
|
|
_jobstore_plugins = ...
|
|
else:
|
|
_trigger_plugins = ...
|
|
_executor_plugins = ...
|
|
_jobstore_plugins = ...
|
|
_trigger_classes = ...
|
|
_executor_classes = ...
|
|
_jobstore_classes = ...
|
|
def __init__(self, gconfig=..., **options) -> None:
|
|
...
|
|
|
|
def __getstate__(self):
|
|
...
|
|
|
|
def configure(self, gconfig=..., prefix=..., **options): # -> None:
|
|
"""
|
|
Reconfigures the scheduler with the given options.
|
|
|
|
Can only be done when the scheduler isn't running.
|
|
|
|
:param dict gconfig: a "global" configuration dictionary whose values can be overridden by
|
|
keyword arguments to this method
|
|
:param str|unicode prefix: pick only those keys from ``gconfig`` that are prefixed with
|
|
this string (pass an empty string or ``None`` to use all keys)
|
|
:raises SchedulerAlreadyRunningError: if the scheduler is already running
|
|
|
|
"""
|
|
...
|
|
|
|
def start(self, paused=...): # -> None:
|
|
"""
|
|
Start the configured executors and job stores and begin processing scheduled jobs.
|
|
|
|
:param bool paused: if ``True``, don't start job processing until :meth:`resume` is called
|
|
:raises SchedulerAlreadyRunningError: if the scheduler is already running
|
|
:raises RuntimeError: if running under uWSGI with threads disabled
|
|
|
|
"""
|
|
...
|
|
|
|
@abstractmethod
|
|
def shutdown(self, wait=...): # -> None:
|
|
"""
|
|
Shuts down the scheduler, along with its executors and job stores.
|
|
|
|
Does not interrupt any currently running jobs.
|
|
|
|
:param bool wait: ``True`` to wait until all currently executing jobs have finished
|
|
:raises SchedulerNotRunningError: if the scheduler has not been started yet
|
|
|
|
"""
|
|
...
|
|
|
|
def pause(self): # -> None:
|
|
"""
|
|
Pause job processing in the scheduler.
|
|
|
|
This will prevent the scheduler from waking up to do job processing until :meth:`resume`
|
|
is called. It will not however stop any already running job processing.
|
|
|
|
"""
|
|
...
|
|
|
|
def resume(self): # -> None:
|
|
"""Resume job processing in the scheduler."""
|
|
...
|
|
|
|
@property
|
|
def running(self): # -> bool:
|
|
"""
|
|
Return ``True`` if the scheduler has been started.
|
|
|
|
This is a shortcut for ``scheduler.state != STATE_STOPPED``.
|
|
|
|
"""
|
|
...
|
|
|
|
def add_executor(self, executor, alias=..., **executor_opts): # -> None:
|
|
"""
|
|
Adds an executor to this scheduler.
|
|
|
|
Any extra keyword arguments will be passed to the executor plugin's constructor, assuming
|
|
that the first argument is the name of an executor plugin.
|
|
|
|
:param str|unicode|apscheduler.executors.base.BaseExecutor executor: either an executor
|
|
instance or the name of an executor plugin
|
|
:param str|unicode alias: alias for the scheduler
|
|
:raises ValueError: if there is already an executor by the given alias
|
|
|
|
"""
|
|
...
|
|
|
|
def remove_executor(self, alias, shutdown=...): # -> None:
|
|
"""
|
|
Removes the executor by the given alias from this scheduler.
|
|
|
|
:param str|unicode alias: alias of the executor
|
|
:param bool shutdown: ``True`` to shut down the executor after
|
|
removing it
|
|
|
|
"""
|
|
...
|
|
|
|
def add_jobstore(self, jobstore, alias=..., **jobstore_opts): # -> None:
|
|
"""
|
|
Adds a job store to this scheduler.
|
|
|
|
Any extra keyword arguments will be passed to the job store plugin's constructor, assuming
|
|
that the first argument is the name of a job store plugin.
|
|
|
|
:param str|unicode|apscheduler.jobstores.base.BaseJobStore jobstore: job store to be added
|
|
:param str|unicode alias: alias for the job store
|
|
:raises ValueError: if there is already a job store by the given alias
|
|
|
|
"""
|
|
...
|
|
|
|
def remove_jobstore(self, alias, shutdown=...): # -> None:
|
|
"""
|
|
Removes the job store by the given alias from this scheduler.
|
|
|
|
:param str|unicode alias: alias of the job store
|
|
:param bool shutdown: ``True`` to shut down the job store after removing it
|
|
|
|
"""
|
|
...
|
|
|
|
def add_listener(self, callback, mask=...): # -> None:
|
|
"""
|
|
add_listener(callback, mask=EVENT_ALL)
|
|
|
|
Adds a listener for scheduler events.
|
|
|
|
When a matching event occurs, ``callback`` is executed with the event object as its
|
|
sole argument. If the ``mask`` parameter is not provided, the callback will receive events
|
|
of all types.
|
|
|
|
:param callback: any callable that takes one argument
|
|
:param int mask: bitmask that indicates which events should be
|
|
listened to
|
|
|
|
.. seealso:: :mod:`apscheduler.events`
|
|
.. seealso:: :ref:`scheduler-events`
|
|
|
|
"""
|
|
...
|
|
|
|
def remove_listener(self, callback): # -> None:
|
|
"""Removes a previously added event listener."""
|
|
...
|
|
|
|
def add_job(self, func, trigger=..., args=..., kwargs=..., id=..., name=..., misfire_grace_time=..., coalesce=..., max_instances=..., next_run_time=..., jobstore=..., executor=..., replace_existing=..., **trigger_args): # -> Job:
|
|
"""
|
|
add_job(func, trigger=None, args=None, kwargs=None, id=None, \
|
|
name=None, misfire_grace_time=undefined, coalesce=undefined, \
|
|
max_instances=undefined, next_run_time=undefined, \
|
|
jobstore='default', executor='default', \
|
|
replace_existing=False, **trigger_args)
|
|
|
|
Adds the given job to the job list and wakes up the scheduler if it's already running.
|
|
|
|
Any option that defaults to ``undefined`` will be replaced with the corresponding default
|
|
value when the job is scheduled (which happens when the scheduler is started, or
|
|
immediately if the scheduler is already running).
|
|
|
|
The ``func`` argument can be given either as a callable object or a textual reference in
|
|
the ``package.module:some.object`` format, where the first half (separated by ``:``) is an
|
|
importable module and the second half is a reference to the callable object, relative to
|
|
the module.
|
|
|
|
The ``trigger`` argument can either be:
|
|
#. the alias name of the trigger (e.g. ``date``, ``interval`` or ``cron``), in which case
|
|
any extra keyword arguments to this method are passed on to the trigger's constructor
|
|
#. an instance of a trigger class
|
|
|
|
:param func: callable (or a textual reference to one) to run at the given time
|
|
:param str|apscheduler.triggers.base.BaseTrigger trigger: trigger that determines when
|
|
``func`` is called
|
|
:param list|tuple args: list of positional arguments to call func with
|
|
:param dict kwargs: dict of keyword arguments to call func with
|
|
:param str|unicode id: explicit identifier for the job (for modifying it later)
|
|
:param str|unicode name: textual description of the job
|
|
:param int misfire_grace_time: seconds after the designated runtime that the job is still
|
|
allowed to be run (or ``None`` to allow the job to run no matter how late it is)
|
|
:param bool coalesce: run once instead of many times if the scheduler determines that the
|
|
job should be run more than once in succession
|
|
:param int max_instances: maximum number of concurrently running instances allowed for this
|
|
job
|
|
:param datetime next_run_time: when to first run the job, regardless of the trigger (pass
|
|
``None`` to add the job as paused)
|
|
:param str|unicode jobstore: alias of the job store to store the job in
|
|
:param str|unicode executor: alias of the executor to run the job with
|
|
:param bool replace_existing: ``True`` to replace an existing job with the same ``id``
|
|
(but retain the number of runs from the existing one)
|
|
:rtype: Job
|
|
|
|
"""
|
|
...
|
|
|
|
def scheduled_job(self, trigger, args=..., kwargs=..., id=..., name=..., misfire_grace_time=..., coalesce=..., max_instances=..., next_run_time=..., jobstore=..., executor=..., **trigger_args): # -> Callable[..., Any]:
|
|
"""
|
|
scheduled_job(trigger, args=None, kwargs=None, id=None, \
|
|
name=None, misfire_grace_time=undefined, \
|
|
coalesce=undefined, max_instances=undefined, \
|
|
next_run_time=undefined, jobstore='default', \
|
|
executor='default',**trigger_args)
|
|
|
|
A decorator version of :meth:`add_job`, except that ``replace_existing`` is always
|
|
``True``.
|
|
|
|
.. important:: The ``id`` argument must be given if scheduling a job in a persistent job
|
|
store. The scheduler cannot, however, enforce this requirement.
|
|
|
|
"""
|
|
...
|
|
|
|
def modify_job(self, job_id, jobstore=..., **changes):
|
|
"""
|
|
Modifies the properties of a single job.
|
|
|
|
Modifications are passed to this method as extra keyword arguments.
|
|
|
|
:param str|unicode job_id: the identifier of the job
|
|
:param str|unicode jobstore: alias of the job store that contains the job
|
|
:return Job: the relevant job instance
|
|
|
|
"""
|
|
...
|
|
|
|
def reschedule_job(self, job_id, jobstore=..., trigger=..., **trigger_args):
|
|
"""
|
|
Constructs a new trigger for a job and updates its next run time.
|
|
|
|
Extra keyword arguments are passed directly to the trigger's constructor.
|
|
|
|
:param str|unicode job_id: the identifier of the job
|
|
:param str|unicode jobstore: alias of the job store that contains the job
|
|
:param trigger: alias of the trigger type or a trigger instance
|
|
:return Job: the relevant job instance
|
|
|
|
"""
|
|
...
|
|
|
|
def pause_job(self, job_id, jobstore=...):
|
|
"""
|
|
Causes the given job not to be executed until it is explicitly resumed.
|
|
|
|
:param str|unicode job_id: the identifier of the job
|
|
:param str|unicode jobstore: alias of the job store that contains the job
|
|
:return Job: the relevant job instance
|
|
|
|
"""
|
|
...
|
|
|
|
def resume_job(self, job_id, jobstore=...): # -> None:
|
|
"""
|
|
Resumes the schedule of the given job, or removes the job if its schedule is finished.
|
|
|
|
:param str|unicode job_id: the identifier of the job
|
|
:param str|unicode jobstore: alias of the job store that contains the job
|
|
:return Job|None: the relevant job instance if the job was rescheduled, or ``None`` if no
|
|
next run time could be calculated and the job was removed
|
|
|
|
"""
|
|
...
|
|
|
|
def get_jobs(self, jobstore=..., pending=...): # -> list[Any]:
|
|
"""
|
|
Returns a list of pending jobs (if the scheduler hasn't been started yet) and scheduled
|
|
jobs, either from a specific job store or from all of them.
|
|
|
|
If the scheduler has not been started yet, only pending jobs can be returned because the
|
|
job stores haven't been started yet either.
|
|
|
|
:param str|unicode jobstore: alias of the job store
|
|
:param bool pending: **DEPRECATED**
|
|
:rtype: list[Job]
|
|
|
|
"""
|
|
...
|
|
|
|
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
|
|
|
|
"""
|
|
...
|
|
|
|
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
|
|
|
|
"""
|
|
...
|
|
|
|
def remove_all_jobs(self, jobstore=...): # -> None:
|
|
"""
|
|
Removes all jobs from the specified job store, or all job stores if none is given.
|
|
|
|
:param str|unicode jobstore: alias of the job store
|
|
|
|
"""
|
|
...
|
|
|
|
def print_jobs(self, jobstore=..., out=...): # -> None:
|
|
"""
|
|
print_jobs(jobstore=None, out=sys.stdout)
|
|
|
|
Prints out a textual listing of all jobs currently scheduled on either all job stores or
|
|
just a specific one.
|
|
|
|
:param str|unicode jobstore: alias of the job store, ``None`` to list jobs from all stores
|
|
:param file out: a file-like object to print to (defaults to **sys.stdout** if nothing is
|
|
given)
|
|
|
|
"""
|
|
...
|
|
|
|
def export_jobs(self, outfile, jobstore=...): # -> None:
|
|
"""
|
|
Export stored jobs as JSON.
|
|
|
|
:param outfile: either a file object opened in text write mode ("w"), or a path
|
|
to the target file
|
|
:param jobstore: alias of the job store to export jobs from (if omitted, export
|
|
from all configured job stores)
|
|
|
|
"""
|
|
...
|
|
|
|
def import_jobs(self, infile, jobstore=...): # -> None:
|
|
"""
|
|
Import jobs previously exported via :meth:`export_jobs.
|
|
|
|
:param infile: either a file object opened in text read mode ("r") or a path to
|
|
a JSON file containing previously exported jobs
|
|
:param jobstore: the alias of the job store to import the jobs to
|
|
|
|
"""
|
|
...
|
|
|
|
@abstractmethod
|
|
def wakeup(self): # -> None:
|
|
"""
|
|
Notifies the scheduler that there may be jobs due for execution.
|
|
Triggers :meth:`_process_jobs` to be run in an implementation specific manner.
|
|
"""
|
|
...
|
|
|
|
|
|
|