Result
Awaiting jobs and reading typed results.
Awaiting jobs and reading typed results.
String id = flexiq.enqueue(add, payload);
flexiq.awaitJob(id, Duration.ofSeconds(30)); // block until terminal
Optional<Integer> sum = flexiq.getResult(id, Integer.class); // 5awaitJob(id, timeout) polls the store until the job reaches a terminal state
(COMPLETE, DEAD, or CANCELLED) and returns its Optional<Job> snapshot;
it throws a FlexiQException if the timeout elapses first. Any process
sharing the storage can await a job by id.
| Method | Description |
|---|---|
getResult(id) → Optional<byte[]> | The raw serialized result, if complete. |
getResult(id, Class<R>) → Optional<R> | The result deserialized with the queue's serializer. |
Both return Optional.empty() while the job is still pending or running — pair
them with awaitJob (or an EventName.SUCCESS listener on the worker) when
you need to block.
Empty is also what a job whose result TTL has expired looks like, and what
a DEAD or CANCELLED job looks like: neither produced a result. So an empty
Optional is "no value to read", never "the job succeeded with nothing". When
the difference matters, unwrap the job snapshot and read its status —
getJob(id).map(job -> job.status).
The raw overload is the escape hatch, not the normal path. Reach for it to re-encode a result under a different serializer, to forward bytes without decoding them, or to inspect a payload a codec chain wrapped. Everything else wants the typed overload, which applies the same serializer the worker used to write it — a mismatch there is what turns a working task into a decode error at the reader.
Job snapshotgetJob(id) returns the job's current state without waiting:
flexiq.getJob(id).ifPresent(job -> {
System.out.println(job.status); // JobStatus.RUNNING
System.out.println(job.progress); // 0–100, if reported
System.out.println(job.error); // last error, if any
});Job carries id, queue, taskName, status, priority, createdAt,
scheduledAt, startedAt, completedAt, retryCount, maxRetries,
timeoutMs, progress, error, uniqueKey, namespace, and metadata.
All timestamps are Unix milliseconds.
awaitJob is for waiting on one job (tests, request/response bridges). To
scan many jobs use listJobs(JobFilter); for aggregate outcomes use
metrics(taskName, sinceMs).