coravel icon indicating copy to clipboard operation
coravel copied to clipboard

Allow queue job status reporting

Open Corstiaan84 opened this issue 4 years ago • 9 comments

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:

  1. Queue job
  2. Get job id
  3. Use job id to subscribe to events
  4. Receive instance of (custom) type through an event
  5. Do some cool progress reporting back onto a UI thread or something.

Corstiaan84 avatar Jun 19 '20 12:06 Corstiaan84

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!

jamesmh avatar Jun 26 '20 03:06 jamesmh

I am having a trouble understanding this. From the example - where do I put that TaskStartedListener class? How does it connects to the queue?

leqwasd avatar Aug 25 '20 17:08 leqwasd

Check out the event listener docs: https://docs.coravel.net/Events/#listeners

Let me know if that helps 👍

jamesmh avatar Aug 25 '20 17:08 jamesmh

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.

leqwasd avatar Aug 25 '20 17:08 leqwasd

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.

leqwasd avatar Aug 25 '20 18:08 leqwasd

Sorry about that 😅. That's really great feedback! I'll add some more details to that part of the docs 🐱‍🏍

jamesmh avatar Aug 26 '20 11:08 jamesmh

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)

mdissel avatar Oct 06 '20 07:10 mdissel

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?

jamesmh avatar Oct 06 '20 11:10 jamesmh

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..

mdissel avatar Oct 07 '20 11:10 mdissel