dispatchSync method
Dispatches a job and processes it synchronously (blocks until done).
Useful for testing or when you need the result immediately. Timeout is enforced if the job defines one.
Implementation
Future<void> dispatchSync(Job job) async {
Logger.staticInfo('⚡ Processing [${job.name}] synchronously');
job.attempts++;
job.status = JobStatus.processing;
try {
final timeoutVal = job.timeout;
if (timeoutVal != null) {
await job.handle().timeout(
timeoutVal,
onTimeout: () {
throw JobTimeoutException(job.id, job.name, timeoutVal);
},
);
} else {
await job.handle();
}
job.status = JobStatus.completed;
job.finishedAt = DateTime.now();
} catch (error, stackTrace) {
job.lastError = error;
job.status = JobStatus.failed;
job.finishedAt = DateTime.now();
await job.onFailure(error, stackTrace);
rethrow;
}
}