From 33ee624ad48971974617cc5c9f184197b4a1a162 Mon Sep 17 00:00:00 2001 From: JeyBee Date: Mon, 20 Jan 2025 21:55:06 +0100 Subject: [PATCH] Add queue cli option (#295) --- pgqueuer/cli.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pgqueuer/cli.py b/pgqueuer/cli.py index 3bc3ffd..7b653be 100644 --- a/pgqueuer/cli.py +++ b/pgqueuer/cli.py @@ -328,5 +328,30 @@ async def run_async() -> None: asyncio_run(run_async()) +@app.command(help="Manually enqueue a job into the PGQueuer system.") +def queue( + ctx: Context, + entrypoint: str = typer.Argument( + ..., + help="The entry point of the job to be executed.", + ), + payload: None | str = typer.Argument( + None, + help="Optional payload for the job. Can be any serialized data (e.g., JSON or a string)", + ), +) -> None: + config: AppConfig = ctx.obj + + async def run_async() -> None: + await (await query_adapter(config.dsn)).enqueue( + entrypoint, + None if payload is None else payload.encode(), + priority=0, + execute_after=timedelta(seconds=0), + ) + + asyncio_run(run_async()) + + if __name__ == "__main__": app(prog_name="pgqueuer")