Skip to main content

Scheduler middleware for ASGI frameworks

Project description

Orloj

Format Python version License Top Languages Size Last commit

Orloj banner

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

orloj-0.1.4.tar.gz (4.4 kB view hashes)

Uploaded Source

Built Distribution

orloj-0.1.4-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page