coravel
coravel copied to clipboard
Allow queue job status reporting
Hi James,
If I'm not mistaken Coravel currently does not support a default method to poll for or subscribe to the status and/or progress of queued jobs.
What would be cool if, after queueing an invocable, some sort of job id was returned. This id could be stored for later reference and used to get the progress or status of the invocable.
Or/and some sort of pub/sub or event raising system where, from inside the invocable, events can be raised (with a custom type, like MySuperCoolInvocableProgressObj) that broadcasts status updates from inside Invoke()
.
So something like:
- Queue job
- Get job id
- Use job id to subscribe to events
- Receive instance of (custom) type through an event
- Do some cool progress reporting back onto a UI thread or something.
K, so this is in preview so you'll have to play around and let me know if this works 😅 Also, does the API work well? Or is it too cumbersome? etc.
You'll have to install the preview version manually -> https://www.nuget.org/packages/Coravel/4.0.0-preview2
Then, check out the docs here -> https://docs.coravel.net/Queuing/#tracking-task-progress
That should give you the ability to notify the UI when a specific job is started & completed.
Let me know how that goes!
I am having a trouble understanding this. From the example - where do I put that TaskStartedListener
class? How does it connects to the queue?
Check out the event listener docs: https://docs.coravel.net/Events/#listeners
Let me know if that helps 👍
I don't get it. I created a class:
public class TaskStartedListener: IListener<QueueTaskStarted>
{
public Task HandleAsync(QueueTaskStarted broadcasted)
{
System.Diagnostics.Debug.WriteLine($"QueueTaskStarted {broadcasted.Guid}");
return Task.CompletedTask;
}
}
In my ConfigureServices
I have
services.AddScoped<UpdateSets>();
services.AddScoped<TaskStartedListener>();
UpdateSets
implements IInvocable
And I call it from the action like this:
var guid = _queue.QueueInvocable<UpdateSets>();
The tasks gets enqueued, and executed, but it never hits HandleAsync
of TaskStartedListener
.
All right, I figured I had to register it like this:
var provider = app.ApplicationServices;
IEventRegistration registration = provider.ConfigureEvents();
registration.Register<QueueTaskStarted>().Subscribe<TaskStartedListener>();
You should add some help text about registering event listeners in the section of https://docs.coravel.net/Queuing/#tracking-task-progress
I could understand - that I would need to register my events, and my listeners for my own events. It was unclear - what to do with built in ones.
Sorry about that 😅. That's really great feedback! I'll add some more details to that part of the docs 🐱🏍
If I'm not mistaken Coravel currently does not support a default method to poll for or subscribe to the status and/or progress of queued jobs.
Any updates on this request? something like queue.GetProgress(Guid id) and a job can update the progress (percentage and custom message)
You can use event listeners to get the progress as "push" model (vs. "pull") -> https://docs.coravel.net/Queuing/#tracking-task-progress
Not sure this is something I want to add as a "pull" model since that can be done right now by updating some shared storage/memory whenever the event listeners are triggered. You can choose to store that in a database, in memory or just send the data via signal if you want?
With a pull model I mean that in my asp.net UI a progressbar is shown and every x seconds there's a request to pull the current progress/status. Maybe the current queue implementation can hold a dictionary with the guid as key and an object holding the current progress..