InfiniticWorker class manages the execution of workflows and tasks in Infinitic. Workers process messages from the message broker, execute tasks and workflow logic, and manage workflow state.
Package
Constructor
The worker configuration including transport, storage, and service/workflow definitions
Creation Methods
From Builder
From YAML
Creates a worker from YAML files in the resources directoryParameters:
resources: String...- Resource paths
Creates a worker from YAML files in the file systemParameters:
files: String...- File paths
Creates a worker from YAML stringsParameters:
yamls: String...- YAML content strings
Instance Methods
Lifecycle Management
Starts the worker synchronously (blocks current thread)This method starts all configured consumers and begins processing messages. It blocks until the worker is closed or an error occurs.Example:
Starts the worker asynchronouslyReturns: A CompletableFuture that completes when the worker is fully startedExample:
Stops the worker gracefullyCancels all message consumers and waits for ongoing messages to complete processing within the configured grace period. Automatically called on JVM shutdown.Example:
Properties
Built-in Infinitic client for dispatching workflows and tasksWorkers have access to a client instance that shares the same transport configuration, useful for starting child workflows or dispatching tasks.Example:
The worker configuration
Worker Architecture
The worker manages several types of components:Service Executors
Execute task implementations:- Process
ExecuteTaskmessages - Run user-defined service methods
- Handle retries and timeouts
- Support batch processing
Workflow Executors
Execute workflow logic:- Process workflow tasks
- Run workflow methods
- Manage workflow state transitions
- Handle deterministic execution
Tag Engines
Manage workflow and task tags:- Map tags to IDs
- Handle tag-based queries
- Maintain tag indexes in storage
State Engines
Manage workflow state:- Store and retrieve workflow state
- Process state transitions
- Handle workflow commands
- Manage timers and signals
Configuration
Workers are configured with:- Transport: Message broker configuration (Pulsar, In-Memory)
- Storage: State storage configuration (Redis, PostgreSQL, MySQL, In-Memory)
- Services: Task service definitions with concurrency and retry policies
- Workflows: Workflow definitions with state engine and tag engine settings
- Event Listeners: Optional event listeners for monitoring
Usage Example
Example with Async Start
Graceful Shutdown
Whenclose() is called, the worker:
- Stops accepting new messages
- Waits for ongoing messages to complete (up to
shutdownGracePeriodSeconds) - Logs statistics about in-flight messages
- Closes executors and transport connections
- Deletes temporary resources
Monitoring
The worker logs detailed information about:- Startup configuration (concurrency, storage, timeouts)
- Message processing (received, in-flight, completed)
- Errors and retries
- Shutdown statistics
Thread Safety
TheInfiniticWorker manages internal thread pools for:
- Message consumption (coroutines)
- Task execution (executor services)
- Workflow execution (executor services)
Error Handling
The worker handles errors through:- Automatic retries: Based on retry policies
- Dead letter queues: For messages that cannot be processed
- Graceful degradation: Failed components don’t affect others
- Logging: Comprehensive error logging with context
See Also
- Worker Configuration - For configuration options
- Transport Configuration - For message broker setup
- Storage Configuration - For state storage setup
- Workflow - For implementing workflows