Gator is a convenient wrapper around procrastinate which provides a basic web UI through a starlette app which can be used to extend functionality, for instance adding endpoints to trigger tasks asynchronously.
Gator Tasks are basically a Python script file which lives into the task/
folder, they share the same Gator's namespace, therefore dependencies for new tasks will be installed as Gator dependencies, a nozzle_vendorised
folder is included on Gator's namespace so the python modules it contains can be shared between tasks, in the same way it could be added other folders to share common code between tasks.
Once a new task is added, Gator needs to be restarted in order to load it.
It can do anything that one would achieve using Python.
1- Create a python file into /tasks
2- The entry point for the task can be any async Python function decorated with app.task
, i.e.
@app.task(pass_context=True)
async def get_time(ctx: procrastinate.job_context.JobContext) -> None:
res = httpx.get("https://worldtimeapi.org/api/timezone/Europe/London")
res.raise_for_status()
with open("my_time_result.json", "w+") as file:
file.write(json.dumps(res.json()))
3- make the function accessible by Gator, adding an entry to the file tasks/__init__.py
i.e.
import_paths=[
"nozzle.gator.tasks.get_time"
]
4