Workers
Stateless, autonomous processors that execute discrete business tasks.
Responsibilities
Task Execution
- Process job cards from message queues
- Execute single, focused business operations
- Use Bridge for all data and state access
- Report results and metrics
Autonomous Operation
- Self-manage workload consumption
- Handle errors and retries independently
- Scale based on queue depth
- Exit gracefully when replaced
Stateless Processing
- Maintain no persistent state between jobs
- Fetch all required data from Bridge
- Complete each job independently
- Can be stopped/started without impact
Lifecycle
1. Startup
Connect to base infrastructure (via Bridge) Register with assigned community Send initial heartbeat Begin consumption cycle
2. Processing Cycle (the Loop)
Continuous loop of:
beat → getJobs → process → optimize → repeat
3. Graceful Shutdown
- Stop accepting new jobs
- Complete current jobs
- Send final heartbeat
- Close connections cleanly
The Worker Cycle
Beat (Heartbeat)
Worker announces its presence and health. Automated managed action through the worker framework. When developing a worker you don't need to manage this process.
Get Jobs
Worker fetches available work from its queue. Batching, caching and retry/recovery are managed actions through the worker framework. When developing a worker you don't need to manage this process.
Process Jobs
This invokes the work() function within the extension framework. Here is where the business logic is added through a series of modular functions (tasks).
Task Functions
The core control method processJobs manages the complete job processing lifecycle:
Purpose: Provides robust, fault-tolerant batch processing with automatic error handling and retry logic.
What it does:
- Receives: A batch of job cards and a processor function
- Batch Processing: Processes each job card in the batch through the provided function
- Retry Logic: Automatically retries failed jobs up to 3 times with exponential backoff
- Error Management: Catches and handles errors without stopping the entire batch
- Failure Management: Stops batch processing only if a job fails after all retries
- Timeout Protection: Prevents jobs from hanging with configurable timeouts
- Status Tracking: Updates job card status (Processed/Error) based on results
- Returns: The complete batch of job cards with updated statuses
Configuration Options:
maxRetries: Number of retry attempts (default: 3)retryDelay: Delay between retries (default: 1000ms)timeout: Maximum execution time per job (default: 5000ms)
State Management: The worker state management model requires adding the outcome of each task to jobCard.data so it is passed on to the next task while maintaining multi-job batch simplicity.