Configuration
How to configure Swig for your needs
Configuration
Queue Configuration
Swig allows you to configure multiple queues with different worker pools:
Each queue operates independently with its own worker pool, allowing you to:
- Process priority jobs faster with dedicated workers
- Prevent low-priority jobs from blocking important tasks
- Scale worker pools based on queue requirements
Worker Configuration
Workers must implement the Worker interface:
Example worker implementation:
Worker Registration
Workers must be registered with Swig before they can process jobs:
The registry stores a factory for each worker type. Every claimed job gets a fresh worker instance before its JSON payload is unmarshaled, which avoids sharing mutable worker state across concurrent jobs.
Job Options
When adding jobs, you can specify various options:
Batch Processing
Swig supports efficient batch job insertion:
Transactional Batch Processing
Batch jobs can also be inserted within a transaction:
Transaction Support
Swig integrates seamlessly with your existing transactions:
Error Handling
Swig provides comprehensive error handling:
- Failed jobs are automatically retried with exponential backoff
- Maximum retry attempts can be configured
- Error details are stored in the database for debugging
Connection Lifecycle
Swig uses PostgreSQL features that are tied to a database session, so it keeps those responsibilities on dedicated connections:
- Worker notifications use a long-lived
LISTEN/NOTIFYlistener per worker. - Leader election uses a dedicated advisory-lock connection for the active leader.
- Shutdown cancels worker contexts, closes listeners, waits for workers, and releases the leader advisory lock from the same session that acquired it.
Application queries and job inserts still use the normal driver pool. Dedicated connections are only used where PostgreSQL requires session ownership.
Cleanup and Testing
Swig provides methods for both graceful shutdown and complete cleanup:
The Close method is particularly useful in:
- Testing environments to clean up after tests
- Development scenarios to reset state
- CI/CD pipelines needing clean slate between runs
Example usage in tests:
Next Steps
- Examples - See Swig in action with practical examples
- API Reference - Detailed API documentation