feat: Add multi-process worker support with Redis-based task storage #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implements multi-process worker support by storing task execution details in Redis instead of in-memory dictionaries.
Problem
Current implementation stores task payloads (
func,args,kwargs) in process-local memory (worker_pool._tasks), which breaks when running multiple worker processes:This makes Kew incompatible with common production patterns like Uvicorn/Gunicorn with
--workers N > 1.Solution
Store task payloads in Redis using
cloudpickleserialization, enabling any worker process to execute any task.Key Changes
1. Task Payload Storage (
submit_task)func/args/kwargswithcloudpickle.dumps()task_payload:{task_id}with base64 encoding (fordecode_responses=Truecompatibility)TASK_EXPIRY_SECONDS)2. Task Execution (
_process_queue)worker_pool._taskscloudpickle.loads()3. Circuit Breaker Configuration
max_circuit_breaker_failuresparameter toQueueConfig4. Cleanup Improvements
task_payload:*keys after task completionTASK_PAYLOAD_PREFIXconstant for consistencyBackward Compatibility
QueueConfigparameters compatible (new param has default)Testing
Tested in production with:
Dependencies
cloudpickle>=3.0.0for robust function/closure serializationChecklist
Related Issues
Implements roadmap item: "Distributed workers with coordination (locks) for multi-process scaling"