Skip to content

aekasitt/orloj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 uv package manager as such:

uv 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:

pyenv shell 3.8.18
uv venv --python-preference system
source .venv/bin/activate
uv sync --dev

Acknowledgements

License

This project is licensed under the terms of the MIT license.

About

Scheduler middleware for ASGI frameworks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages