apscheduler-di-0.1.0
توضیحات
Lightweight and beneficial Dependency Injection plugin for apscheduler
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | apscheduler-di-0.1.0 |
| نام | apscheduler-di |
| نسخه کتابخانه | 0.1.0 |
| نگهدارنده | ['GLEF1X'] |
| ایمیل نگهدارنده | ['glebgar567@gmail.com'] |
| نویسنده | Gleb Garanin |
| ایمیل نویسنده | glebgar567@gmail.com |
| آدرس صفحه اصلی | - |
| آدرس اینترنتی | https://pypi.org/project/apscheduler-di/ |
| مجوز | MIT |
# Implementation of dependency injection for `apscheduler`
[](https://pypi.org/project/apscheduler-di/)[](https://codecov.io/gh/GLEF1X/apscheduler-di)[](https://pepy.tech/project/apscheduler-di)
### Motivation:
* `apscheduler-di` solves the problem since `apscheduler` 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](https://www.python.org/dev/peps/pep-0561/))
* Extend `apscheduler` and provide handy aliases for events(such as `on_startup`, `on_shutdown` and
etc)
* Provide an opportunity to implement [Dependency Inversion](https://en.wikipedia.org/wiki/Dependency_inversion_principle) SOLID principle
"Under the hood" `apscheduler-di` just
implements [Decorator](https://en.wikipedia.org/wiki/Decorator_pattern) pattern and wraps up the
work of native `BaseScheduler` using [rodi](https://github.com/Neoteroi/rodi) lib
### Quick example:
```python
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()
```
نیازمندی
| مقدار | نام |
|---|---|
| >=3.8.1,<4.0.0 | APScheduler |
| >=2.0.0,<3.0.0 | rodi |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.7,<4.0 | Python |
نحوه نصب
نصب پکیج whl apscheduler-di-0.1.0:
pip install apscheduler-di-0.1.0.whl
نصب پکیج tar.gz apscheduler-di-0.1.0:
pip install apscheduler-di-0.1.0.tar.gz