Scheduler middleware for ASGI frameworks
Project description
Orloj
Getting started
You can use orloj simply by installing via pip on your Terminal.
pip install orloj
or alternatively when using poetry package manager as such:
poetry add orloj
And then you can begin using OrlojMiddleware in your ASGI project as such
...
from orloj import OrlojMiddleware
def action() -> None:
"""Action to be called by scheduler"""
app.add_middleware(OrlojMiddleware, interval=3, job=action, job_id="scheduled-action")
...
The following example shows you how to setup OrlojMiddleware to run scheduled tasks alongside
your FastAPI application.
from fastapi import FastAPI
from logging import Logger, getLogger
from orloj import OrlojMiddleware
from starlette.responses import PlainTextResponse, RedirectResponse
app = FastAPI()
logger: Logger = getLogger("uvicorn")
def hello_name(name: str) -> None:
logger.info(f"Hello, {name}!")
def hello_world() -> None:
logger.info("Hello, World!")
@app.get("/")
async def redirect_to_swagger_docs() -> RedirectResponse:
"""Redirects to swagger documentation
"""
return RedirectResponse("/docs")
@app.get("/health", response_class=PlainTextResponse, status_code=200)
async def health() -> str:
"""Health check
"""
return "OK"
app.add_middleware(
OrlojMiddleware, interval=3, job=hello_name, job_id="hello-igor", name="Igor"
)
app.add_middleware(
OrlojMiddleware, interval=6, job=hello_world, job_id="hello-world"
)
Dependencies
Contributions
To contribute to the project, fork the repository and clone to your local device and development dependencies including three extra libraries not included in final builds as such:
- mypy - Optional static typing for Python
- pytest - The pytest framework makes it easy to write small tests, yet scales to support complex functional testing
- ruff - An extremely fast Python linter and code formatter, written in Rust.
Use the following commands to setup your local environment with development dependencies:
pip install --user poetry
poetry install --with dev
Acknowledgements
License
This project is licensed under the terms of the MIT license.
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
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 orloj-0.1.4.tar.gz.
File metadata
- Download URL: orloj-0.1.4.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.0 Darwin/22.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56c466eb1c3f9dd4554c3c5af8edc1f4ae06be891bfdc0ad9c30c010548eb0a6
|
|
| MD5 |
2e20ffae470b4d863b6699acfc45ded0
|
|
| BLAKE2b-256 |
af097aa45b012a983ea72d422c7a60b1353b33e75351d3f906e412a8045bbac0
|
File details
Details for the file orloj-0.1.4-py3-none-any.whl.
File metadata
- Download URL: orloj-0.1.4-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.0 Darwin/22.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d65f21de6e53dd79117e42a633745f6b6b943f8cfd9871247e6b12aee37d8ac
|
|
| MD5 |
dc90f1c9d99adefed084110132753ca3
|
|
| BLAKE2b-256 |
4d56a5e0ebae2a3c90f3bd160eaa068e6ce448ac3a05bc22b840372937b5d1ab
|