janbjorge / PgQueuer

PgQueuer is a Python library leveraging PostgreSQL for efficient job queuing.

Home Page:https://pgqueuer.readthedocs.io/en/latest/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸš€ PgQueuer - Building Smoother Workflows One Queue at a Time πŸš€

CI pypi downloads versions


πŸ“š Documentation: Explore the Docs πŸ“–

πŸ” Source Code: View on GitHub πŸ’Ύ


PgQueuer

PgQueuer is a minimalist, high-performance job queue library for Python, leveraging the robustness of PostgreSQL. Designed for simplicity and efficiency, PgQueuer uses PostgreSQL's LISTEN/NOTIFY to manage job queues effortlessly.

Features

  • Simple Integration: Easy to integrate with existing Python applications using PostgreSQL.
  • Efficient Concurrency Handling: Utilizes PostgreSQL's FOR UPDATE SKIP LOCKED for reliable and concurrent job processing.
  • Real-time Notifications: Leverages LISTEN and NOTIFY for real-time updates on job status changes.

Installation

To install PgQueuer, simply install with pip the following command:

pip install PgQueuer

Example Usage

Here's how you can use PgQueuer in a typical scenario processing incoming data messages:

import asyncio

import asyncpg
from PgQueuer.db import AsyncPGDriver
from PgQueuer.models import Job
from PgQueuer.qm import QueueManager


async def main() -> None:
    connection = await asyncpg.connect()
    driver = AsyncPGDriver(connection)
    qm = QueueManager(driver)

    # Setup the 'fetch' entrypoint
    @qm.entrypoint("fetch")
    async def process_message(job: Job) -> None:
        print(f"Processed message: {job}")

    N = 1_000
    # Enqueue jobs.
    await qm.queries.enqueue(
        ["fetch"] * N,
        [f"this is from me: {n}".encode() for n in range(N)],
        [0] * N,
    )

    await qm.run()


if __name__ == "__main__":
    asyncio.run(main())

About

PgQueuer is a Python library leveraging PostgreSQL for efficient job queuing.

https://pgqueuer.readthedocs.io/en/latest/index.html

License:MIT License


Languages

Language:Python 98.9%Language:Dockerfile 0.7%Language:Shell 0.4%