Lightweight and beneficial Dependency Injection plugin for apscheduler
Project description
Implementation of dependency injection for apscheduler
Motivation:
apscheduler-disolves the problem sinceapschedulerdoesn'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
apschedulerand provide handy aliases for events(such ason_startup,on_shutdownand 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_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, some_argument: int):
print(tack)
def main():
scheduler = ContextSchedulerDecorator(BlockingScheduler(jobstores=job_stores))
scheduler.ctx.add_instance(Tack(), Tack)
scheduler.add_executor('processpool')
scheduler.add_job(tick, 'interval', seconds=3, kwargs={"some_argument": 5})
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.1.0.tar.gz
(8.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file apscheduler_di-0.1.0.tar.gz.
File metadata
- Download URL: apscheduler_di-0.1.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.11.0 Darwin/22.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc98b38a38829bc4974b3f0436e62bccd3c51989ad3e9646244110258b3e4f33
|
|
| MD5 |
8c817542a0233824b8c0ec84c92061b3
|
|
| BLAKE2b-256 |
da8a2422c8d892cee3968e69039a66f57ff915d021f7566b787fcc8b44816a03
|
File details
Details for the file apscheduler_di-0.1.0-py3-none-any.whl.
File metadata
- Download URL: apscheduler_di-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.11.0 Darwin/22.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aaeda49f4f9c5a4cdd3dcb9498e3431eecfedce50e05ccf77861cca70bfb44bc
|
|
| MD5 |
fd9e6437253946b3921ddc5ef8c5485a
|
|
| BLAKE2b-256 |
037bd39f91d965b4c18bc0baab9d202f9e3dbbb827ab33e5750fb650cd4e842b
|