No project description provided
Project description
Implementation of dependency injection for apscheduler
Prerequisites:
apscheduler-di
solves the problem sinceapscheduler
doesn't support Dependency Injection natively, and it's real problem for developers to pass on complicated objects to jobs without corruptions
Features:
- Supports type hints (PEP 561)
- Extend
apscheduler
and provide handy aliases for events(such ason_startup
,on_shutdown
and etc) - Provide an opportunity to implement Dependency Inversion SOLID principle
"Under the hood" apscheduler-di
just
implements Decorator pattern and wraps up the
work of native BaseScheduler
using rodi lib
Quick example:
import os
from typing import Dict
from apscheduler.jobstores.redis import RedisJobStore
from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler_di import ContextSchedulerDecorator
# pip install redis
job_defaults: Dict[str, RedisJobStore] = {
"default": RedisJobStore(
jobs_key="dispatched_trips_jobs", run_times_key="dispatched_trips_running"
)
}
job_stores: Dict[str, RedisJobStore] = {
"default": RedisJobStore(
jobs_key="dispatched_trips_jobs", run_times_key="dispatched_trips_running"
)
}
class Tack:
def tack(self):
print("Tack!")
def tick(tack: Tack):
print(tack)
def main():
scheduler = ContextSchedulerDecorator(BlockingScheduler(jobstores=job_stores,
job_defaults=job_defaults))
scheduler.ctx.add_instance(Tack(), Tack)
scheduler.add_executor('processpool')
scheduler.add_job(tick, 'interval', seconds=3)
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
try:
scheduler.start()
except (KeyboardInterrupt, SystemExit):
pass
if __name__ == '__main__':
main()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
apscheduler-di-0.0.1.tar.gz
(7.3 kB
view hashes)
Built Distribution
Close
Hashes for apscheduler_di-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 677f00f1d710b8df7fd45377f68d58af4c55ad58dc7b12593f2b6f926e438422 |
|
MD5 | 0d87946ad5313a9aaf0b0b57bdb952c8 |
|
BLAKE2b-256 | 23262da9242a944c36a421603990a4644c0e94382fe223d6bf71c5a6371e973c |