Mini-Worker
A simple, parameter-driven worker framework with internal loops and file-based monitoring.
Features
- Parameter-driven: No external configuration files required - all settings passed as parameters
- Internal loops: Workers run continuously with configurable wait times between iterations
- File-based monitoring: Status and logs written to specified directories
- Process tracking: Creates worker_id files with process IDs for monitoring
- Worker management: Built-in manager for starting, stopping, and monitoring workers
- Simple CLI: Easy command-line interface for running workers
- Flexible execution: Support for batch processing and continuous operation
- Statistics tracking: Built-in performance monitoring and rate calculation
- Compatibility: Drop-in replacement for existing worker systems
Installation
pip install mini-worker
Quick Start
1. Create a Worker
from mini_worker import BaseMiniWorker
class MyWorker(BaseMiniWorker):
def __init__(self, **kwargs):
super().__init__(**kwargs)
# Initialize your worker-specific components
# Dependencies are imported normally - no injection needed!
def do_work(self):
"""Implement your work logic here"""
with self.track_operation('my_operation'):
print("Doing some work...")
# Your actual work logic
def get_worker_id(self):
return "my_worker"
2. Run via CLI
# Run worker with 5-minute intervals
mini-worker run --worker-class=MyWorker --log-dir=/var/log/workers --wait-seconds=300
# Run with custom parameters
mini-worker run --worker-class=MyWorker --log-dir=/tmp/logs --wait-seconds=60 \
--worker-params='{"param1": "value1", "param2": 123}'
3. Run Programmatically
worker = MyWorker(
worker_id="my_worker_001",
log_dir="/var/log/workers",
stats_dir="/var/log/workers",
wait_seconds=300
)
worker.run()
4. Use Worker Manager
from mini_worker import MiniWorkerManager
# Create manager
manager = MiniWorkerManager(log_dir="/var/log/workers")
# Register workers
manager.register_worker("my_worker", "mymodule.MyWorker")
# Start worker
manager.start_worker_with_params("my_worker", {"param1": "value1"})
# Check status
status = manager.get_worker_status("my_worker")
# Stop worker
manager.stop_worker("my_worker")
CLI Commands
mini-worker run
Run a worker directly.
Options:
--worker-class: Python class name of the worker to run (required)--log-dir: Directory for log files (default: current directory)--stats-dir: Directory for stats files (default: same as log-dir)--wait-seconds: Seconds to wait between work cycles (default: 600)--worker-params: JSON string of worker-specific parameters--max-cycles: Maximum number of work cycles before stopping (default: unlimited)--worker-id: Override worker ID (default: use worker class default)
mini-worker status
Check worker status.
Options:
--stats-dir: Directory containing stats files (default: current directory)--worker-id: Show status for specific worker ID--format: Output format - 'text' or 'json' (default: text)
Monitoring
Mini-worker creates several files for monitoring:
{worker_id}.log: Worker log file with rotating logs{worker_id}.stats: Human-readable statistics{worker_id}.json: Detailed statistics in JSON format{worker_id}.pid: Process ID file for monitoring
Migration from Existing Workers
Mini-worker is designed as a drop-in replacement for existing worker systems:
# Before (existing worker)
from src.workers.base_worker import BaseWorker
class MyWorker(BaseWorker):
def __init__(self):
super().__init__()
# Same initialization code
def do_work(self):
with self.calc_one('my_operation'):
# Same work logic
pass
# After (mini-worker)
from mini_worker import BaseMiniWorker
class MyWorker(BaseMiniWorker):
def __init__(self, **kwargs):
super().__init__(**kwargs)
# Same initialization code
def get_worker_id(self):
return "my_worker"
def do_work(self):
with self.calc_one('my_operation'): # Still works!
# Same work logic
pass
Key changes:
- Import
BaseMiniWorkerinstead ofBaseWorker - Add
**kwargsto__init__and callsuper().__init__(**kwargs) - Implement
get_worker_id()method calc_one()still works for compatibility, or usetrack_operation()
Examples
See the examples/ directory for complete working examples.
License
MIT License
Metadata
Release files for mini-worker 0.1.1
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 | |
|---|---|---|---|---|
| mini_worker-0.1.1.tar.gz | 35.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mini_worker-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 53.0 kB
Release files / mini_worker-0.1.1.tar.gz
| Download URL | mini_worker-0.1.1.tar.gz |
|---|---|
| Size | 35.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
05a693a9866e822a73b98d05cd7e4cf6aae1904b1f62d6da6a09c33fd14bcd0f
|
|
BLAKE2b-256 checksum How to use checksums |
b61dd7492778668fce7afc3f17b750b2d45f6144f5b8bb0d707ea67fccdb14af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / mini_worker-0.1.1-py3-none-any.whl
| Download URL | mini_worker-0.1.1-py3-none-any.whl |
|---|---|
| Size | 17.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4edc7d03ec0d1cb6071123376e35e5a3f723572396406a53108ff9e9f9f6d614
|
|
BLAKE2b-256 checksum How to use checksums |
aa7d99c0b7274478c9bc320e7151dc4ea485a23925052db638be830a6bb43c47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Security for mini-worker 0.1.1
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.