Timed Batch Worker
Python library for efficiently batch-processing workloads asynchronously with batch-size- and time-based flushes using short-circuiting events.
Installation
pip install timed-batch-worker
Usage
from timed_batch_worker import TimedBatchWorker
# Handle the batched items
def handle_batch(items):
http.post('/api/logs/bulk', data=items)
# Create a worker that flushes the queue when:
# 1. The batch contains 20 objects, or
# 2. Five seconds have passed since the last flush
worker = TimedBatchWorker(
handler=handle_batch,
flush_interval=5,
flush_batch_size=20,
)
# Worker started in separate thread to avoid throttling main event loop
# in case the batch handler includes synchronous workloads.
worker.start()
# Add objects to the current batch at any time
@app.get('/users/create')
def create_user():
...
# Hand off an object to the worker
worker.enqueue({
'event': 'USER_CREATED',
'data': user
})
...
Metadata
Release files for timed-batch-worker 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| timed-batch-worker-0.0.5.tar.gz | 4.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| timed_batch_worker-0.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.8 kB
Release files / timed-batch-worker-0.0.5.tar.gz
| Download URL | timed-batch-worker-0.0.5.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e7a70c1ccea2ed51fbccde8a002d07982511ef7255d231f29f129c315a8fd374
|
|
BLAKE2b-256 checksum How to use checksums |
e29947a6a4a28848779c0013fe79e1989bd25ee355848c684e741bfa3709dc5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.6
|
Release files / timed_batch_worker-0.0.5-py3-none-any.whl
| Download URL | timed_batch_worker-0.0.5-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fd87d810c3e01d603541ff6f289996b20b46f71e364e1aac7b060b0a198f6020
|
|
BLAKE2b-256 checksum How to use checksums |
9cd514865be26e7ade6dbf14a880d7ec7824c9bb9c2d67b2be0161d41cea1528
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.6
|