Reads from a Laravel queue
Project description
Laravel Queue for Python
Currently:
- only supports reading
- only supports queues in postgres
Create a Queue Object
from laravel-queue import Queue
connection_string = "postgresql://user:password@host:5432/db"
queue = Queue(connection_string)
Queue Args:
connection: str or sqlalchemy.engine.base.Engine
queue: str, default 'python', the queue name in the database
jobs_table: str, default 'jobs.jobs', the table name for the jobs
failed_jobs_table: str, default 'jobs.failed_jobs', the table name for the failed jobs
Read Jobs from Queue
queue.read() ## List of jobs returned, or:
jobs = queue.jobs ## List of jobs in queue object
Running Jobs
for job in queue.jobs:
job.run(function, arg, kwarg=kwarg) ## run any function and pass any args to it
function can be any function to run for this job any args and kwargs will be used in this function
EX:
job.run(print, job.id)
Output: 12345
Jobs run in this way will be:
- removed from the jobs table and the queue object when complete (regardless of pass or fail)
- if failed, added to the failed jobs table along with the exception and a timestamp
Managing Jobs Manually
For some reason, you may want to manage the job state yourself. (bypassing the run function above)
## Job failed
job.fail(exception) # Takes a string of the exception message, and fails the job. (both in the db and the queue)
## Job success
job.complete() # Removes from job table and queue object
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
laravel_queue-0.0.11.tar.gz
(4.4 kB
view hashes)
Built Distribution
Close
Hashes for laravel_queue-0.0.11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50e7976e1f4d7d18c50e5b9aa4832b95c0c60f31b8ae16a12f19048187ca6cc4 |
|
MD5 | 255e385092c4d87f29b694dc9befd0ac |
|
BLAKE2b-256 | f2888ad4e95ec479941644f08cde9a1c16d270739c3e20143d2be65beb0ab956 |