### Install Raquel Job Queue Source: https://github.com/vduseev/raquel/blob/main/README.md Installs the Raquel library for Python job queues. Includes an option to install with asyncio support, which adds the 'greenlet' package as a dependency. ```bash pip install raquel pip install raquel[asyncio] ``` -------------------------------- ### Create Jobs Table - Database Setup Source: https://context7.com/vduseev/raquel/llms.txt Demonstrates multiple methods for creating the necessary `jobs` table in your database. It includes using `create_all()`, Alembic migrations, and raw SQL for PostgreSQL. ```python from raquel import Raquel # Method 1: Using create_all() (recommended) rq = Raquel("postgresql+psycopg2://postgres:postgres@localhost/postgres") rq.create_all() # Safe to call multiple times # Method 2: Using Alembic migrations # In your alembic/env.py: from raquel.models.base_sql import BaseSQL as RaquelBaseSQL def run_migrations_offline(): context.configure( target_metadata=[target_metadata, RaquelBaseSQL.metadata], ) # Then run: alembic revision --autogenerate -m "add raquel jobs table" # Method 3: Raw SQL for PostgreSQL """ CREATE TABLE IF NOT EXISTS jobs ( id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), queue TEXT NOT NULL, payload TEXT, status TEXT NOT NULL DEFAULT 'queued', max_age BIGINT, max_retry_count INTEGER, min_retry_delay INTEGER DEFAULT 1000, max_retry_delay INTEGER DEFAULT 43200000, backoff_base INTEGER DEFAULT 1000, enqueued_at BIGINT NOT NULL DEFAULT extract(epoch from now()) * 1000, scheduled_at BIGINT NOT NULL DEFAULT extract(epoch from now()) * 1000, attempts INTEGER NOT NULL DEFAULT 0, error TEXT, error_trace TEXT, claimed_by TEXT, claimed_at BIGINT, finished_at BIGINT ); CREATE INDEX IF NOT EXISTS idx_jobs_queue ON jobs (queue); CREATE INDEX IF NOT EXISTS idx_jobs_status ON jobs (status); CREATE INDEX IF NOT EXISTS idx_jobs_scheduled_at ON jobs (scheduled_at); """ ``` -------------------------------- ### GET /queues Source: https://github.com/vduseev/raquel/blob/main/README.md Retrieve a list of all active queues in the system. ```APIDOC ## GET /queues ### Description Returns a list of all queue names currently present in the jobs table. ### Method GET ### Endpoint /queues ### Response #### Success Response (200) - **queues** (array) - List of queue names #### Response Example ["default", "tasks"] ``` -------------------------------- ### GET /stats Source: https://github.com/vduseev/raquel/blob/main/README.md Retrieve comprehensive statistics for all queues. ```APIDOC ## GET /stats ### Description Returns a summary of job counts per status for all queues. ### Method GET ### Endpoint /stats ### Response #### Success Response (200) - **stats** (object) - Map of queue names to their respective status counts. #### Response Example { "default": { "total": 10, "queued": 10, "failed": 0 } } ``` -------------------------------- ### Get Job Statistics Per Queue in Raquel Source: https://github.com/vduseev/raquel/blob/main/README.md Provides detailed statistics for jobs within a queue, including total, queued, claimed, success, and failed counts. Accessible through Python and SQL. ```python >>> rq.stats() {'default': QueueStats(name='default', total=10, queued=10, claimed=0, success=0, failed=0, expired=0, exhausted=0, cancelled=0)} ``` ```sql SELECT queue, status, COUNT(*) FROM jobs GROUP BY queue, status ``` -------------------------------- ### GET /jobs/retry-logic Source: https://github.com/vduseev/raquel/blob/main/README.md Explains the calculation logic for job retries, including backoff strategies and delay capping. ```APIDOC ## GET /jobs/retry-logic ### Description Retrieves information on how the system calculates retry delays for failed jobs. ### Method GET ### Endpoint /jobs/retry-logic ### Logic - **Formula**: `backoff_base * 2 ^ attempt` - **Constraints**: Actual delay is clamped between `min_retry_delay` (default 1s) and `max_retry_delay` (default 12h). - **Units**: All durations are in milliseconds. ### Response #### Success Response (200) - **backoff_base** (integer) - The base multiplier for exponential backoff. - **min_retry_delay** (integer) - Minimum allowed delay in ms. - **max_retry_delay** (integer) - Maximum allowed delay in ms. ``` -------------------------------- ### GET /jobs Source: https://context7.com/vduseev/raquel/llms.txt Retrieves jobs from one or more queues, ordered by scheduled time. ```APIDOC ## GET /jobs ### Description Fetches all jobs from the specified queues, sorted by scheduled time (newest first). ### Method GET ### Endpoint /jobs ### Parameters #### Query Parameters - **queues** (list) - Required - One or more queue names. ### Response #### Success Response (200) - **jobs** (list) - A list of job objects containing id, status, and payload. ``` -------------------------------- ### GET /queues Source: https://context7.com/vduseev/raquel/llms.txt Retrieves a list of all queue names currently containing jobs. ```APIDOC ## GET /queues ### Description Returns a list of all queue names that have jobs associated with them. ### Method GET ### Endpoint /queues ### Response #### Success Response (200) - **queue_names** (list) - A list of strings representing active queue names. #### Response Example ["default", "emails", "reports"] ``` -------------------------------- ### Reschedule Jobs for Future Execution Source: https://github.com/vduseev/raquel/blob/main/README.md Shows how to use the reschedule method within a dequeue context to delay job processing. Includes examples for specific timestamps, time deltas, and millisecond delays. ```python with rq.dequeue("my-queue") as job: if not is_everything_ready_to_process(job.payload): job.reschedule(delay=timedelta(minutes=10)) else: do_work(job.payload) # Specific scheduling examples with rq.dequeue("my-queue") as job: job.reschedule(at=datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) + timedelta(days=1)) with rq.dequeue("my-queue") as job: job.reschedule(delay=500) ``` -------------------------------- ### Asynchronous Job Operations Source: https://github.com/vduseev/raquel/blob/main/README.md Provides examples of using AsyncRaquel for non-blocking enqueue and dequeue operations in an asyncio environment. ```python import asyncio from raquel import AsyncRaquel rq = AsyncRaquel("postgresql+asyncpg://postgres:postgres@localhost/postgres") async def main(): await rq.enqueue("tasks", {'my': {'name_is': 'Slim Shady'}}) async with rq.dequeue("tasks") as job: if job: await do_work(job.payload) else: await asyncio.sleep(1) asyncio.run(main()) ``` -------------------------------- ### Get Specific Queue Statistics Source: https://context7.com/vduseev/raquel/llms.txt Fetches statistics for specified queues. This function allows you to get detailed job counts for particular queues by passing their names as arguments. ```python email_stats = rq.stats("emails", "notifications") ``` -------------------------------- ### GET /count Source: https://context7.com/vduseev/raquel/llms.txt Counts the number of jobs in a specific queue, with optional filtering by status. ```APIDOC ## GET /count ### Description Counts jobs in a queue. Supports filtering by single or multiple statuses. ### Method GET ### Endpoint /count ### Parameters #### Query Parameters - **queue** (string) - Required - The name of the queue. - **status** (string/list) - Optional - The status or list of statuses to filter by (e.g., QUEUED, FAILED). ### Response #### Success Response (200) - **count** (integer) - The number of jobs matching the criteria. ``` -------------------------------- ### Get All Queue Statistics Source: https://context7.com/vduseev/raquel/llms.txt Retrieves and prints statistics for all active queues. It iterates through the returned dictionary and displays total, queued, claimed, success, failed, expired, exhausted, and cancelled job counts for each queue. ```python all_stats = rq.stats() for queue_name, stats in all_stats.items(): print(f"Queue: {queue_name}") print(f" Total: {stats.total}") print(f" Queued: {stats.queued}") print(f" Claimed: {stats.claimed}") print(f" Success: {stats.success}") print(f" Failed: {stats.failed}") print(f" Expired: {stats.expired}") print(f" Exhausted: {stats.exhausted}") print(f" Cancelled: {stats.cancelled}") ``` -------------------------------- ### Initialize Raquel Queue Connection Source: https://context7.com/vduseev/raquel/llms.txt Demonstrates how to connect to a SQL database and initialize the jobs table using both synchronous and asynchronous clients. ```python from raquel import Raquel # Connect to PostgreSQL rq = Raquel("postgresql+psycopg2://postgres:postgres@localhost/postgres") # Or use SQLite for development rq = Raquel("sqlite:///jobs.db") # Create the jobs table rq.create_all() ``` ```python import asyncio from raquel import AsyncRaquel rq = AsyncRaquel("postgresql+asyncpg://postgres:postgres@localhost/postgres") async def main(): await rq.create_all() await rq.enqueue("tasks", {"message": "Hello async!"}) asyncio.run(main()) ``` -------------------------------- ### Enqueue Jobs with Scheduling and Configuration Source: https://context7.com/vduseev/raquel/llms.txt Shows how to add jobs to the queue with various options, including immediate execution, delayed scheduling, and custom retry policies. ```python from raquel import Raquel from datetime import datetime, timedelta rq = Raquel("postgresql+psycopg2://postgres:postgres@localhost/postgres") rq.create_all() # Simple immediate job job = rq.enqueue("emails", {"to": "user@example.com", "subject": "Welcome"}) # Schedule job for later execution job = rq.enqueue( queue="reports", payload={"report_type": "daily", "date": "2024-01-15"}, at=datetime.now() + timedelta(hours=1) ) # Job with delay and retry limits job = rq.enqueue( queue="api-calls", payload={"url": "https://api.example.com/webhook"}, delay=timedelta(minutes=5), max_retry_count=3, max_age=timedelta(hours=24), min_retry_delay=5000, max_retry_delay=timedelta(hours=1), backoff_base=2000 ) ``` -------------------------------- ### POST /jobs/create_all Source: https://github.com/vduseev/raquel/blob/main/README.md Initializes the necessary database schema for Raquel jobs. This method is idempotent and safe to execute multiple times. ```APIDOC ## POST /jobs/create_all ### Description Initializes the jobs table in the configured database. It automatically detects the database dialect and applies the appropriate schema. ### Method POST ### Endpoint /jobs/create_all ### Request Example ```python # Using the Python library rq.create_all() ``` ### Response #### Success Response (200) - **status** (string) - Confirmation that the table was created or already exists. ``` -------------------------------- ### Initialize Jobs Table with Raquel Source: https://github.com/vduseev/raquel/blob/main/README.md Uses the library's built-in method to automatically create the necessary database tables for job tracking. This method is idempotent and safe to execute multiple times. ```python rq.create_all() ``` -------------------------------- ### Process Jobs with Raquel dequeue() Source: https://github.com/vduseev/raquel/blob/main/README.md Illustrates how to pick up and process jobs using the Raquel dequeue() context manager. It handles job claiming, status updates, exceptions, and retries automatically. Includes a loop with a sleep mechanism for when no jobs are available. ```python import time from raquel import Raquel # Assuming rq is an initialized Raquel instance rq = Raquel("postgresql+psycopg2://postgres:postgres@localhost/postgres") def do_work(payload): # Replace with your actual job processing logic print(f"Processing payload: {payload}") while True: with rq.dequeue("tasks") as job: if job: do_work(job.payload) else: time.sleep(1) ``` -------------------------------- ### Schedule Jobs using SQL INSERT Source: https://github.com/vduseev/raquel/blob/main/README.md Shows how to schedule jobs by directly inserting rows into the 'jobs' table using SQL. This method requires knowledge of the database schema and UUID generation. ```sql -- Schedule 3 jobs in the "my-jobs" queue for immediate processing INSERT INTO jobs (id, queue, status, payload) VALUES (uuid_generate_v4(), 'my-jobs', 'queued', '{"my": "payload"}'), (uuid_generate_v4(), 'my-jobs', 'queued', '101'), (uuid_generate_v4(), 'my-jobs', 'queued', 'Is this the real life?'); ``` -------------------------------- ### Configure Alembic for Raquel Migrations Source: https://github.com/vduseev/raquel/blob/main/README.md Integrates Raquel's database metadata into an existing Alembic migration workflow. This allows for automatic schema management by adding the Raquel base metadata to the target_metadata list in env.py. ```python from raquel.models.base_sql import BaseSQL as RaquelBaseSQL # Inside context.configure target_metadata=[ target_metadata, RaquelBaseSQL.metadata, ] ``` -------------------------------- ### Schedule Jobs with Raquel enqueue() Source: https://github.com/vduseev/raquel/blob/main/README.md Demonstrates scheduling jobs using the Raquel enqueue() method. Jobs can be assigned to specific queues and can have JSON-serializable payloads or simple strings. Requires a SQLAlchemy connection string or engine. ```python from raquel import Raquel rq = Raquel("postgresql+psycopg2://postgres:postgres@localhost/postgres") rq.enqueue(queue="messages", payload="Hello, World!") rq.enqueue(queue="tasks", payload={"data": [1, 2]}) ``` -------------------------------- ### Handle Job Failures with Context Manager Source: https://github.com/vduseev/raquel/blob/main/README.md Demonstrates how the dequeue context manager automatically handles exceptions by retrying jobs. It also shows how to manually trigger a failure to initiate a retry. ```python with rq.dequeue("my-queue") as job: raise Exception("Oh no") do_work(job.payload) with rq.dequeue("my-queue") as job: try: do_work(job.payload) except Exception as e: job.fail(str(e)) ``` -------------------------------- ### Low-Level Job Claiming and Releasing Source: https://context7.com/vduseev/raquel/llms.txt Provides low-level methods for manually claiming and releasing jobs. While `dequeue()` is recommended for most use cases, `claim()` and `unclaim()` offer finer control for advanced scenarios. ```python from raquel import Raquel rq = Raquel("sqlite:///jobs.db") # Manually claim a job (advanced usage) job = rq.claim("tasks", claim_as="manual-worker") if job: try: process(job.payload) rq.resolve(job.id, attempt_num=1) except Exception as e: rq.fail(job, attempt_num=1, exception=e) # Release a claimed job without processing rq.unclaim(job.id) ``` -------------------------------- ### Marking Jobs as Failed Source: https://context7.com/vduseev/raquel/llms.txt Demonstrates how to manually mark a job as failed within a context manager, triggering exponential backoff. It also shows that unhandled exceptions are automatically caught and marked as failed. ```python from raquel import Raquel rq = Raquel("sqlite:///jobs.db") while True: with rq.dequeue("tasks") as job: if job: try: result = external_api_call(job.payload) if not result.success: job.fail("API returned error status") except Exception as e: job.fail(e) with rq.dequeue("tasks") as job: if job: raise ValueError("Something went wrong") ``` -------------------------------- ### List Queues in Raquel Source: https://github.com/vduseev/raquel/blob/main/README.md Retrieves a list of all available queues in the Raquel system. Supports both Python and SQL interfaces. ```python >>> rq.queues() ['default', 'tasks'] ``` ```sql SELECT queue FROM jobs GROUP BY queue ``` -------------------------------- ### Dequeue and Process Jobs Source: https://context7.com/vduseev/raquel/llms.txt Demonstrates worker loops using the dequeue context manager to claim and process jobs from one or multiple queues. ```python import time from raquel import Raquel rq = Raquel("postgresql+psycopg2://postgres:postgres@localhost/postgres") # Basic worker loop while True: with rq.dequeue("emails") as job: if job: print(f"Processed job {job.id}") else: time.sleep(1) # Process from multiple queues with priority while True: with rq.dequeue("high-priority", "default", claim_as="worker-1") as job: if job: print(f"Processing {job.queue} job") ``` ```python import asyncio from raquel import AsyncRaquel rq = AsyncRaquel("postgresql+asyncpg://postgres:postgres@localhost/postgres") async def worker(): while True: async with rq.dequeue("tasks", claim_as="async-worker") as job: if job: print(f"Processed: {job.payload}") else: await asyncio.sleep(1) asyncio.run(worker()) ``` -------------------------------- ### Reject Jobs for Immediate Reassignment Source: https://github.com/vduseev/raquel/blob/main/README.md Demonstrates using the reject method to release a job back to the queue so it can be claimed by another worker. ```python with rq.dequeue("my-queue") as job: if job.payload.get("requires_admin"): job.reject() else: do_work(job.payload) ``` -------------------------------- ### Worker Subscriptions Source: https://context7.com/vduseev/raquel/llms.txt Demonstrates the subscribe decorator for creating synchronous and asynchronous workers. It shows how to process jobs from specific queues and handle graceful shutdown. ```python from raquel import Raquel, Job, StopSubscription rq = Raquel("postgresql+psycopg2://postgres:postgres@localhost/postgres") rq.create_all() @rq.subscribe("emails", "notifications", claim_as="email-worker", sleep=500) def process_message(job: Job): if job.payload.get("type") == "shutdown": raise StopSubscription rq.run_subscriptions() ``` ```python import asyncio from raquel import AsyncRaquel, Job rq = AsyncRaquel("postgresql+asyncpg://postgres:postgres@localhost/postgres") @rq.subscribe("async-tasks", claim_as="async-worker") async def process_async(job: Job): await asyncio.sleep(0.1) async def main(): await rq.create_all() await rq.run_subscriptions() asyncio.run(main()) ``` -------------------------------- ### Generate Alembic Migration Source: https://github.com/vduseev/raquel/blob/main/README.md Command-line instruction to generate a new database migration file based on the updated metadata configuration. ```shell alembic revision --autogenerate -m "raquel" ``` -------------------------------- ### Monitor Job Queue Statuses via SQL Source: https://context7.com/vduseev/raquel/llms.txt These SQL queries allow for the inspection of the jobs table to determine queue distribution, identify failed processes, and track jobs currently in progress or rescheduled. They are intended for use directly against the database backing the Raquel job queue. ```sql -- List all queues with job counts SELECT queue, COUNT(*) FROM jobs GROUP BY queue; -- Failed jobs with errors SELECT id, queue, payload, error, error_trace, attempts FROM jobs WHERE status = 'failed'; -- Jobs currently being processed SELECT id, queue, claimed_by, claimed_at FROM jobs WHERE status = 'claimed'; -- Rescheduled jobs (queued but have previous attempts) SELECT * FROM jobs WHERE status = 'queued' AND attempts > 0 AND claimed_at IS NOT NULL; -- Rejected jobs SELECT * FROM jobs WHERE status = 'queued' AND attempts > 0 AND claimed_at IS NULL; -- Jobs by status count per queue SELECT queue, status, COUNT(*) FROM jobs GROUP BY queue, status; ``` -------------------------------- ### Rejecting Jobs Source: https://context7.com/vduseev/raquel/llms.txt Explains how to release a job back to the queue so another worker can claim it. This is useful when a worker lacks the specific resources required for a task. ```python from raquel import Raquel rq = Raquel("sqlite:///jobs.db") while True: with rq.dequeue("tasks", claim_as="worker-1") as job: if job: if job.payload.get("requires_gpu") and not has_gpu(): job.reject() continue process_job(job.payload) ``` -------------------------------- ### enqueue() - Schedule Jobs Source: https://context7.com/vduseev/raquel/llms.txt Adds a new job to the queue with optional scheduling, retry configurations, and expiration settings. ```APIDOC ## POST /enqueue ### Description Adds a new task to the specified queue. The payload must be a JSON-serializable object. ### Method POST ### Parameters #### Request Body - **queue** (string) - Required - The name of the queue to add the job to. - **payload** (object) - Required - The data to be processed by the worker. - **at** (datetime) - Optional - Specific time to execute the job. - **delay** (timedelta) - Optional - Time to wait before making the job available. - **max_retry_count** (integer) - Optional - Maximum number of retries upon failure. - **max_age** (timedelta) - Optional - Time after which the job expires. ### Request Example { "queue": "emails", "payload": {"to": "user@example.com", "subject": "Welcome"}, "max_retry_count": 3 } ### Response #### Success Response (200) - **id** (string) - The unique identifier of the created job. ``` -------------------------------- ### Queue Monitoring Source: https://context7.com/vduseev/raquel/llms.txt Methods for retrieving job details and queue statistics. ```APIDOC ## get(job_id) ### Description Retrieves the full details of a job, including status, attempts, and payload. ## stats() ### Description Returns statistics regarding job counts by status for configured queues. ``` -------------------------------- ### Query Rejected Jobs in Raquel Source: https://github.com/vduseev/raquel/blob/main/README.md Identifies jobs that were rejected, indicated by a 'queued' status, previous attempts, but no 'claimed_at' timestamp. This query is SQL-based. ```sql SELECT * FROM jobs WHERE status = 'queued' AND attempts > 0 AND claimed_at IS NULL ``` -------------------------------- ### Count Pending and Failed Jobs in Raquel Source: https://github.com/vduseev/raquel/blob/main/README.md Counts jobs that are in a 'queued' or 'failed' state, indicating they are ready to be processed or require attention. Supports Python and SQL. ```python >>> rq.count("default", [rq.QUEUED, rq.FAILED]) 5 ``` ```sql SELECT * FROM jobs WHERE queue = 'default' AND status IN ('queued', 'failed') ``` -------------------------------- ### Job Lifecycle Management Source: https://context7.com/vduseev/raquel/llms.txt Methods to manage individual job states including failing, rescheduling, rejecting, and cancelling. ```APIDOC ## Job.fail(reason) ### Description Marks a job as failed, triggering automatic rescheduling with exponential backoff. ### Parameters - **reason** (str/Exception) - Required - The reason for failure or the exception object. ## Job.reschedule(delay=None, at=None) ### Description Delays job processing to a future time without marking it as failed. ### Parameters - **delay** (timedelta/int) - Optional - Delay duration. - **at** (datetime) - Optional - Specific timestamp for execution. ## Job.reject() ### Description Releases a claimed job back to the queue immediately for other workers to pick up. ## cancel(job_id) ### Description Cancels a pending job that is in 'queued' or 'failed' status. ### Parameters - **job_id** (str) - Required - The unique identifier of the job. ``` -------------------------------- ### Job Lifecycle Management Source: https://context7.com/vduseev/raquel/llms.txt Covers cancelling pending jobs and retrieving job details by ID. These operations allow for fine-grained control and monitoring of the job queue. ```python from raquel import Raquel rq = Raquel("sqlite:///jobs.db") job = rq.enqueue("tasks", {"data": "will be cancelled"}) success = rq.cancel(job.id) retrieved = rq.get(job.id) if retrieved: print(f"Status: {retrieved.status}") ``` -------------------------------- ### Count Jobs Per Queue in Raquel Source: https://github.com/vduseev/raquel/blob/main/README.md Counts the total number of jobs within a specific queue. This functionality is available via Python and SQL. ```python >>> rq.count("default") 10 ``` ```sql SELECT queue, COUNT(*) FROM jobs WHERE queue = 'default' GROUP BY queue ``` -------------------------------- ### List All Queues Source: https://context7.com/vduseev/raquel/llms.txt Retrieves a list of all queue names that currently contain jobs. This is useful for understanding the active queues in your system. ```python from raquel import Raquel rq = Raquel("sqlite:///jobs.db") queue_names = rq.queues() print(f"Active queues: {queue_names}") ``` -------------------------------- ### Rescheduling Jobs Source: https://context7.com/vduseev/raquel/llms.txt Shows how to delay job processing using the reschedule method. Jobs can be rescheduled with a specific delay, a target datetime, or default retry settings. ```python from raquel import Raquel from datetime import datetime, timedelta rq = Raquel("sqlite:///jobs.db") while True: with rq.dequeue("tasks") as job: if job: if not is_ready_to_process(job.payload): job.reschedule(delay=timedelta(minutes=10)) continue job.reschedule(at=datetime(2024, 1, 15, 9, 0, 0)) job.reschedule() job.reschedule(delay=5000) ``` -------------------------------- ### List Jobs from Queues Source: https://context7.com/vduseev/raquel/llms.txt Retrieves all jobs from one or more queues, ordered by their scheduled time with the newest jobs appearing first. This function is useful for fetching jobs to be processed. ```python from raquel import Raquel rq = Raquel("sqlite:///jobs.db") # All jobs in a queue all_jobs = rq.jobs("default") for job in all_jobs: print(f"{job.id}: {job.status} - {job.payload}") # Jobs from multiple queues jobs = rq.jobs("emails", "notifications") ``` -------------------------------- ### dequeue() - Process Jobs Source: https://context7.com/vduseev/raquel/llms.txt Claims the next available job from one or more queues and manages the lifecycle of the task execution. ```APIDOC ## POST /dequeue ### Description Claims the next available job from the specified queues. Uses a context manager to handle status updates, exceptions, and automatic retries. ### Method POST ### Parameters #### Query Parameters - **queues** (list) - Required - List of queue names to poll, ordered by priority. - **claim_as** (string) - Optional - Identifier for the worker claiming the job. ### Response #### Success Response (200) - **job** (object) - The job object containing id, queue, and payload, or null if no jobs are available. ### Response Example { "id": "uuid-string", "queue": "emails", "payload": {"to": "user@example.com"} } ``` -------------------------------- ### Job Status Constants Reference Source: https://context7.com/vduseev/raquel/llms.txt Provides a reference for the job status values used throughout the Raquel API. These constants can be used for querying and filtering jobs based on their current state. ```python from raquel import Raquel rq = Raquel("sqlite:///jobs.db") # Available status constants rq.QUEUED # Job is waiting to be picked up rq.CLAIMED # Job is being processed by a worker rq.SUCCESS # Job completed successfully rq.FAILED # Job failed, will be retried rq.EXPIRED # Job exceeded max_age before processing rq.EXHAUSTED # Job exceeded max_retry_count rq.CANCELLED # Job was manually cancelled # Query jobs by status failed_jobs = rq.count("tasks", rq.FAILED) active_jobs = rq.count("tasks", [rq.QUEUED, rq.FAILED, rq.CLAIMED]) ``` -------------------------------- ### Query Rescheduled Jobs in Raquel Source: https://github.com/vduseev/raquel/blob/main/README.md Identifies jobs that have been rescheduled, characterized by being in a 'queued' status with previous attempts and a 'claimed_at' timestamp. This query is SQL-based. ```sql SELECT * FROM jobs WHERE status = 'queued' AND attempts > 0 AND claimed_at IS NOT NULL ``` -------------------------------- ### Worker Subscriptions Source: https://context7.com/vduseev/raquel/llms.txt Decorators for defining worker functions that process jobs from specific queues. ```APIDOC ## @subscribe(*queues, claim_as=None, sleep=None) ### Description Registers a function as a worker for one or more queues. Supports both synchronous and asynchronous implementations. ### Parameters - **queues** (str) - Required - Queue names to subscribe to. - **claim_as** (str) - Optional - Worker identifier. - **sleep** (int) - Optional - Polling interval in milliseconds. ### Usage ```python @rq.subscribe("tasks") def worker(job): pass ``` ``` -------------------------------- ### Calculate Job Retry Delay Source: https://github.com/vduseev/raquel/blob/main/README.md Calculates the planned retry delay for a job using an exponential backoff formula. The result is typically capped by minimum and maximum delay settings. ```python backoff_base * 2 ^ attempt ``` -------------------------------- ### Count Claimed Jobs in Raquel Source: https://github.com/vduseev/raquel/blob/main/README.md Counts jobs that are currently being processed by a worker (claimed). This is useful for monitoring active job execution. Available in Python and SQL. ```python >>> rq.count("default", rq.CLAIMED) 5 ``` ```sql SELECT * FROM jobs WHERE queue = 'default' AND status = 'claimed' ``` -------------------------------- ### Count Failed Jobs in Raquel Source: https://github.com/vduseev/raquel/blob/main/README.md Retrieves the count of jobs that have failed within a specific queue. Failed jobs can be reprocessed until marked otherwise. Available in Python and SQL. ```python >>> rq.count("default", rq.FAILED) 5 ``` ```sql SELECT * FROM jobs WHERE queue = 'default' AND status = 'failed' ``` -------------------------------- ### POST /expire Source: https://context7.com/vduseev/raquel/llms.txt Manually triggers the expiration process for jobs that have exceeded their maximum age. ```APIDOC ## POST /expire ### Description Forces the expiration of jobs in specified queues that have exceeded their max_age. ### Method POST ### Endpoint /expire ### Parameters #### Request Body - **queues** (list) - Required - List of queue names to process for expiration. ### Response #### Success Response (200) - **expired_count** (integer) - Number of jobs successfully expired. ``` -------------------------------- ### Count Jobs in a Queue Source: https://context7.com/vduseev/raquel/llms.txt Counts the number of jobs within a specified queue. It supports filtering by job status, including single statuses like QUEUED or FAILED, or multiple statuses. ```python from raquel import Raquel rq = Raquel("sqlite:///jobs.db") # Total jobs in queue total = rq.count("default") # Count by specific status pending = rq.count("default", rq.QUEUED) failed = rq.count("default", rq.FAILED) processing = rq.count("default", rq.CLAIMED) # Count multiple statuses ready = rq.count("default", [rq.QUEUED, rq.FAILED]) print(f"Jobs ready to process: {ready}") ``` -------------------------------- ### Expire Old Jobs Source: https://context7.com/vduseev/raquel/llms.txt Manually triggers the expiration of jobs that have exceeded their maximum age (`max_age`). This function helps in cleaning up stale jobs from specified queues. ```python from raquel import Raquel rq = Raquel("sqlite:///jobs.db") # Expire jobs in specific queues expired_count = rq.expire("tasks", "notifications") print(f"Expired {expired_count} jobs") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.