Task
Task.of typed tasks, EnqueueOptions, RetryPolicy, and the annotations.
Task.of typed tasks, EnqueueOptions, RetryPolicy, and the annotations.
import org.byteveda.flexiq.task.Task;
Task<EmailPayload> sendEmail = Task.of("send_email", EmailPayload.class);A Task<T> is an immutable descriptor: a name, the payload type, and default
enqueue options. The fluent option methods each return a new descriptor.
| Method | Description |
|---|---|
Task.of(name, Class<T>) | Payload deserializes to payloadType. |
Task.of(name, TypeReference<T>) | Generic payloads a Class token can't express, e.g. new TypeReference<List<Order>>(){}. |
| Method | Description |
|---|---|
queue(String) | Target queue (default default). |
priority(int) | Higher runs first. |
maxRetries(int) (alias retries) | Attempts before dead-lettering. |
timeoutMs(long) / timeout(Duration) | Per-attempt timeout. |
delayMs(long) / delay(Duration) | Schedule after a delay. |
retryPolicy(RetryPolicy) | Backoff curve — registered with the worker on start(). |
retryOn(Predicate<Throwable>) | Classifies a thrown exception; false dead-letters it immediately. A handler throwing RetryableException / NonRetryableException overrides it. |
codecs(String...) | Named payload codecs applied to this task. |
circuitBreaker(CircuitBreakerConfig) | Trip the task after repeated failures; the worker registers the breaker on start(). |
withOptions(EnqueueOptions) | Replace the default options wholesale. |
Task<EmailPayload> sendEmail = Task.of("send_email", EmailPayload.class)
.queue("emails")
.maxRetries(5)
.timeout(Duration.ofSeconds(30))
.retryPolicy(RetryPolicy.exponential(Duration.ofSeconds(2), Duration.ofMinutes(5)));EnqueueOptionsPer-enqueue overrides, built with EnqueueOptions.builder(); unset fields take
core defaults. Fields: queue, priority, maxRetries, timeoutMs /
timeout(Duration), delayMs / delay(Duration), uniqueKey (alias
jobId) for idempotent enqueues, metadata, namespace, and
dependsOn(String... jobIds) (this job stays pending until the listed jobs
complete successfully; a failed or cancelled dependency cancels it — see
enqueue options).
flexiq.enqueue(sendEmail, payload, EnqueueOptions.builder()
.delay(Duration.ofHours(24))
.uniqueKey("welcome:" + userId)
.build());RetryPolicy| Factory | Description |
|---|---|
exponential(base, max) | Retry N waits about base · 2^N, capped at max, plus jitter. |
delays(Duration...) | Explicit per-attempt delays, applied exactly (no jitter). |
The retry budget comes from maxRetries; the policy only supplies the
timing, which the core scheduler applies durably.
CircuitBreakerConfigGuards a task: after threshold failures inside the rolling window, the
breaker opens and the task is skipped for cooldown before probing again.
Attach with task.circuitBreaker(config); the worker registers it on start().
| Factory / method | Description |
|---|---|
CircuitBreakerConfig.of(int threshold) | Open after threshold failures; other fields default. |
CircuitBreakerConfig.builder(int threshold) | Builder for the full config. |
window(Duration) / windowSeconds(long) | Rolling failure window. |
cooldown(Duration) / cooldownSeconds(long) | How long the breaker stays open. |
halfOpenProbes(int) | Trial jobs admitted while half-open. |
halfOpenSuccessRate(double) | Success fraction among probes needed to close. |
Task<ChargePayload> charge = Task.of("charge", ChargePayload.class)
.circuitBreaker(CircuitBreakerConfig.builder(5)
.window(Duration.ofMinutes(1))
.cooldown(Duration.ofSeconds(30))
.build());Inspect live breaker state with flexiq.listCircuitBreakers()
(workers & hooks).
@TaskHandler marks a method as a task handler. A compile-time processor
(org.byteveda:flexiq ships it as the processor artifact) generates a
FooTasks companion per enclosing class Foo — a typed Task constant per
handler plus bind(Worker.Builder, Foo) and handlers(Foo) — no runtime
reflection.
class Mailer {
@TaskHandler("send_email")
Receipt send(EmailPayload payload, @Resource("smtp") SmtpClient smtp) {
return smtp.deliver(payload);
}
}
Worker worker = flexiq.worker()
.register(MailerTasks.handlers(new Mailer()))
.start();| Annotation | Description |
|---|---|
@TaskHandler(value, queue, maxRetries, timeoutMs, priority) | Task name defaults to the method name; other fields default to the core defaults. |
@Resource("name") | Injects a worker resource into a parameter after the payload. |
@Compressed | Records the "compressed" codec on the generated task. |
@Encrypted | Records the "encrypted" codec — register the actual codec (and key) at runtime. |
All are source-retention: read at compile time, never at runtime.