golemfactory / yagna

An open platform and marketplace for distributed computations
GNU General Public License v3.0
408 stars 63 forks source link

EventSource - fetching batch results by sse loses events #3247

Open mgordel opened 5 months ago

mgordel commented 5 months ago

When I use EventSource to retrieve Batch results, it happens that for quickly executed scripts, e.g. echo Hello World, I am not able to subscribe to events after sending the script and I lose the results for that script.

e.g.

// POST /activity/{activityId}/exec sending `echo Hello World`
const eventSource = new EventSource(`${baseUrl}/activity-api/v1/activity/${activityId}/exec/${batchId}`)
eventSource.addEventListener("runtime", (event) => console.log(event));

I don't get any events in this example. When I change the script to sleep 1 && echo "Hello World" the event appears.

There is a time gap between sending the post and the event subscription in which an event with the result of the batch script is emitted and I am not able to capture this event.

Maybe it would be possible to add a parameter so that I could specify, for example, from what time I would like to receive events... afterTimestamp ?

grisha87 commented 3 months ago

@prekucki , Can we prioritise this? We're having too many cases where we need top put sleep 2 in front of every command to not loose the first events :(