0

The example as shown below is obtained from in https://apscheduler.readthedocs.io/en/stable/userguide.html#configuring-the-scheduler. It demonstrates how to configure a scheduler. But I do not understand what exactly the config is doing.

Question

  1. jobstores has two keys, one using MongoDB, and the other is SQLite. So which one will the scheduler use?

  2. executors has two keys as well, one using ThreadPoolExecutor and the other is ProcessPoolExecutor. Which one would it use? And what is being parallelise (e.g. all the scheduled jobs) ?

from pytz import utc

from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.jobstores.mongodb import MongoDBJobStore
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor


jobstores = {
    'mongo': MongoDBJobStore(),
    'default': SQLAlchemyJobStore(url='sqlite:///jobs.sqlite')
}
executors = {
    'default': ThreadPoolExecutor(20),
    'processpool': ProcessPoolExecutor(5)
}
job_defaults = {
    'coalesce': False,
    'max_instances': 3
}
scheduler = BackgroundScheduler(jobstores=jobstores, executors=executors, job_defaults=job_defaults, timezone=utc)
K_inverse
  • 357
  • 3
  • 16

1 Answers1

0
  1. By default Apscheduler will use a store with the name 'default' if don't specify any when adding jobs (via scheduler.add_job(*args, **kwargs).
  2. The same for executors. It will use a 'default' executor if you don't specify one explicitly when adding jobs.

2.2 "And what is being parallelized (e.g. all the scheduled jobs)?". Yes, but it needs to be mentioned that if you want to run CPU-bound jobs, then you would better use ProcessPoolExecutor. In case you want to run IO-bound jobs then use ThreadPoolExecutor. For more info take a look on this question