pytask
A simple sqlite3-based job queue with a worker. Main purpose is to run jobs in a queue. Jobs are not popped from the queue, which means the queue can act as a history.
Installation
pip install pytask-queue
Usage
The worker will run the function func for each job. The function will be passed a Job object. Which means that you can alter the job object in the function, and the newly updated job will be saved to the queue.
# python process 1
from pytask import Queue, Job, SQLDataType, SQLColumnConditions
queue = Queue(schema=[
("foo", SQLDataType.INTEGER, [SQLColumnConditions.NOT_NULL]),
("bar", SQLDataType.TEXT, [SQLColumnConditions.NOT_NULL]),
("baz", SQLDataType.JSON, [SQLColumnConditions.NOT_NULL])
])
queue.insert(Job(data={"foo": 1, "bar": "test", "baz": {"foo": "bar"}}))
# python process 2
from <relative_file> import queue
from pytask import Job
def func(job: Job):
# Do something with job
job.data["foo"] += 1
worker = Worker(queue, func)
worker.run()
Creating multiple queues or multiple workers is possible. Creating a new queue object won't actually create a new queue, it just creates a new connection to the queue. Which means you can have multiple queue objects pointing to the same queue, or you can use the same queue object for multiple workers.
Be careful to avoid race conditions when using the same queue object for multiple workers.
Flags
Flags are used to configure the behavior of the queue and worker.
Current flags:
auto_convert_json_keys: If True, the queue will automatically convert JSON keys to strings. Useful for retrieving and manipulating JSON data.pop_after_processing: If True, the job will be popped from the queue after processing.
from pytask import Queue, Worker, Job, SQLDataType, SQLColumnConditions, Flags
flags = Flags(auto_convert_json_keys=True, pop_after_processing=True)
queue = Queue(schema=[("foo", SQLDataType.INTEGER, [SQLColumnConditions.NOT_NULL])], flags=flags)
worker = Worker(queue, func, logger=logger)
worker.run()
Concurrent Worker
The concurrent worker is a worker that runs jobs in parallel. It uses a thread pool to run the jobs.
from pytask import Queue, ConcurrentWorker, Job, SQLDataType, SQLColumnConditions
worker = ConcurrentWorker(queue, func, logger=logger, interval=1, max_workers=16)
worker.run()
Metadata
Release files for pytask-queue 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytask_queue-1.0.3.tar.gz | 9.1 kB | Without provenance | Details for pytask_queue-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytask_queue-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for pytask_queue-1.0.3-py3-none-any.whl |
Total release size: 21.1 kB
Release files / pytask_queue-1.0.3.tar.gz
| Download URL | pytask_queue-1.0.3.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e39be0d57ea067f463df757e35901c98db5b009cd9b3eb41fd707d6eaa61b5ec
|
|
BLAKE2b-256 checksum How to use checksums |
20f3837fcf7c4c337baa2124cc83583640f24de804eb947435ba182ab5228596
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.22.1 CPython/3.10.5 Linux/6.5.0-1025-azure
|
Release files / pytask_queue-1.0.3-py3-none-any.whl
| Download URL | pytask_queue-1.0.3-py3-none-any.whl |
|---|---|
| Size | 12.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a49fb1749ab0497b10e417d1c07d60a8cb36c0045a52bfc4e5c0c51a12435d7c
|
|
BLAKE2b-256 checksum How to use checksums |
a335693d63d66fd203b9ac92a24ae7d06eb805c661f123800c9aa5795fa0d473
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.22.1 CPython/3.10.5 Linux/6.5.0-1025-azure
|
Security for pytask-queue 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.