Apscheduler integration for dishka
Project description
APScheduler integration for Dishka
This package provides integration of Dishka dependency injection framework and APScheduler, an advanced Python scheduler.
Installation
pip install apscheduler-dishka
Features
- automatic REQUEST scope management for scheduled jobs
- automatic injection of dependencies into job functions
- support for both sync and async schedulers
- support for
auto_injectmode to automatically wrap all jobs
How to use
- Import
from apscheduler_dishka import (
inject,
setup_dishka,
)
from dishka import make_container, Provider, provide, Scope, FromDishka
- Create provider
class YourProvider(Provider):
@provide(scope=Scope.REQUEST)
def create_interactor(self) -> Interactor:
...
- Mark those of your job function parameters which are to be injected with
FromDishka[]and decorate them using@inject
@inject
def job(
data: str,
interactor: FromDishka[Interactor],
):
...
- Create container
container = make_container(YourProvider())
- Setup
dishkaintegration
from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler_dishka import setup_dishka
scheduler = BlockingScheduler()
setup_dishka(container=container, scheduler=scheduler)
- Add jobs to scheduler
scheduler.add_job(
job,
trigger="interval",
seconds=5,
args=["args"],
)
Auto-inject mode
If you don't want to manually decorate each job with @inject, you can use auto_inject mode:
setup_dishka(
container=container,
scheduler=scheduler,
auto_inject=True,
)
In this mode, all jobs will be automatically wrapped with dependency injection:
def job(
data: str,
interactor: FromDishka[Interactor],
):
...
scheduler.add_job(
job,
trigger="interval",
seconds=5,
args=["args"],
)
Async support
The library supports async schedulers:
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from dishka import make_async_container
from apscheduler_dishka import setup_dishka
scheduler = AsyncIOScheduler()
container = make_async_container(YourProvider())
setup_dishka(container=container, scheduler=scheduler)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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_dishka-1.0.0.tar.gz.
File metadata
- Download URL: apscheduler_dishka-1.0.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac2939867636b3264c65f2dbdc054fc69b71f6bc87760300c2952698824633f9
|
|
| MD5 |
75a83ba91a4748283c44c687fb0cb939
|
|
| BLAKE2b-256 |
751349deaab37b974667289596b88d2ebc688e71fae2dd988411e59c8af39fdb
|
File details
Details for the file apscheduler_dishka-1.0.0-py3-none-any.whl.
File metadata
- Download URL: apscheduler_dishka-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2e03a4afec923e2c959f0645571088b8d14a39b673c28c510714d2b7289973b
|
|
| MD5 |
4e94c8ecc8069f0034e76f980768dfc5
|
|
| BLAKE2b-256 |
062bb6dc5b6745fce425c9ac59cfe746e9f1e69b9c8d7bb07f6813b9df402cca
|