-
|
I plan to use pgqueuer as a mechanism to execute background tasks. The consumer likely would still run as a task in the main application, is this a suitable use case? There are currently three items that I'm concerned and I think pgqueuer might not be handling, but perhaps there are workarounds?
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
Hi there, thanks for the follow-up! You can embed pgqueuer in your main app to drive background tasks, but it’s worth considering resource isolation: if your queue work suddenly spikes, it could consume CPUs or I/O and starve your primary application threads or event loop. To mitigate this you can:
This ensures no more than five instances run in parallel . .
which caps simultaneous tasks across all entrypoints . 1) Exception & retry behaviorBy default, thrown exceptions are caught, logged with status
so any “picked” job whose heartbeat isn’t refreshed within 30 s becomes available again.
2) Connection handling & poolingpgqueuer works over any
3) Log/statistics table growthBy default pgqueuer appends to await queries.clear_queue_log(entrypoint="my_task")
await queries.clear_statistics_log(last=timedelta(days=7))These methods only touch the log tables and won’t interrupt live queue processing. One option is to add a cron job in pgqueuer that will clean the jobs every 24hours or so. 4) CLI command for cleanup (todo?)I could expose a one-off cleanup CLI(meybe something like this?) If it would help? @app.command("cleanup-logs")
def cleanup_logs(
days: int = typer.Option(7, "--days", help="Entries older than this"),
entrypoints: list[str] = typer.Option(None, "-e", help="Entrypoints to target"),
):
async def run():
async with yield_queries(ctx, DBSettings()) as q:
cutoff = timedelta(days=days)
await q.clear_statistics_log(entrypoints)
await q.clear_queue_log(entrypoints)
asyncio_run(run()) |
Beta Was this translation helpful? Give feedback.
-
|
Thank you, this is great. Though, a lot of those things I couldn't find in the documentation, it would be great to include them. I did saw I still think though that the SQS model is safer. I mentioned an exception, but if for example something kills the application then retry time is unlikely to save it. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the feedback – pgqueuer’s docs could definitely use some love. I’m actively trying to find a technical writer to help expand and clarify the documentation. Below is a draft of a Retry & Visibility section that might go into the docs: How
|
Beta Was this translation helpful? Give feedback.
Hi there, thanks for the follow-up! You can embed pgqueuer in your main app to drive background tasks, but it’s worth considering resource isolation: if your queue work suddenly spikes, it could consume CPUs or I/O and starve your primary application threads or event loop. To mitigate this you can:
Cap concurrency at the entrypoint level using
concurrency_limiton the decorator. For example:This ensures no more than five instances run in parallel . .
max_concurrent_tasksparameter onPgQueuer.run():which caps simultaneo…