What are Delegated Tasks?
Delegated tasks allow you to hand off task completion to external systems. Instead of completing synchronously within the service method, delegated tasks:- Start an external process
- Return immediately (the return value is ignored)
- Complete later when the external system calls back
- Integration with external APIs that use webhooks
- Long-running operations managed by external systems
- Event-driven architectures
- Human-in-the-loop workflows
The @Delegated Annotation
Location in source code:io.infinitic.annotations.Delegated
@Delegated annotation marks a service method as delegated. When applied:
- The method’s return value is ignored
- The task remains in a “running” state until explicitly completed
- External systems must call
completeTask()to finish the task
Basic Usage
Completing Delegated Tasks
External systems must complete the task using the Infinitic client:Accessing Task Information
Within a delegated task, you have access to all task context information:Use Cases
Human-in-the-Loop Workflows
Delegated tasks are perfect for workflows requiring human approval:External API Integration
Integrate with third-party services that use webhooks:Long-Running Batch Jobs
Delegate completion to external batch processing systems:Error Handling
Delegated tasks can complete with errors by passing an exception:Storing Task Information
For reliable completion, store task information persistently:Best Practices
Always Store Task Identifiers
Ensure external systems can identify which task to complete:Implement Idempotent Completion
Handle duplicate completion calls gracefully:Set Appropriate Timeouts
Delegated tasks should have timeouts to prevent hanging indefinitely:Monitor Delegated Tasks
Implement monitoring to track delegated task completion rates:Testing Delegated Tasks
Next Steps
Batching
Process multiple tasks efficiently with batch operations
Service Context
Learn more about accessing task information