aekasitt / orloj

Scheduler middleware for ASGI frameworks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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)  # Schedules for 3 second interval
...

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, name="Igor")
app.add_middleware(OrlojMiddleware, interval=6, job=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:

  • black - The uncompromising Python code formatter
  • mypy - Optional static typing for Python
  • pytest - The pytest framework makes it easy to write small tests, yet scales to support complex functional testing

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.

About

Scheduler middleware for ASGI frameworks

License:MIT License


Languages

Language:Python 100.0%