Async Events API - How to get queue job response content?

Hello,

I am using a Queue to perform a series of REST API calls. With the following code from the documentation:

const jobProgress = queue.getJob(jobId);
const response = await jobProgress.getStats();
const { success, inProgress, failed } = await response.json();

I can see only the status of the job, but I want to use the data returned by the job in my app. Currently I store the data in a Storage, and poll on the Storage to check if the data is available.

Does anyone know a better way to obtain the data fetched in the job, that doesn’t involve polling? Is there a way to attach it to the response of jobProgress.getStats() for example?

Thanks in advance!

Kato

Hi @KatoWildiers, if you want to access the payload that you push the async event with, you will need to implement a consumer for your queue.

1 Like

Hi Bo Zhang,

Thank you for your response. I have already implemented a consumer in the same way as in the documentation. I am looking for a way to read the return values of the consumer method. Currently I can only get the stats of the job, which tells me if it is { success, inProgress, failed }. Through logging i can see that when my consumer method returns, the stats value goes from {0,1,0} to {1,0,0}. It is however the value the method returns that I am interested in. Do you understand my question?

Kind regards,

Kato Wildiers

Hi @KatoWildiers, Ahh yes, I understand your question now. Unfortunately, we don’t store what you return from your consumer method. I think the solution you have right now, storing the result in Forge Storage and retrieving it from there, is the right approach. Although, instead of polling on Forge storage, could you correlate the jobId with the result that you store in Forge storage and query Forge storage once the job is in the success state?

1 Like