Search code examples
c#asp.netcqrsquartz.netlong-running-processes

ASP.NET CQRS and long running tasks hosted in external process


I have a web application where users can enqueue tasks to export some data. The process can take up to 2-3 hours but can complete in seconds depending what was requested.

The export process will be handled like that:

public class ExportCommandHandler: IAsyncRequestHandler<ExportCommand, bool>
{
   ...

   public async Task<bool> Handle(ExportCommand message)
   {
      return await _externalScheduler.EnqueueJobAsync(new ExportJob(...));
   }
}

The _externalScheduler.EnqueueJobAsync currently just calls a self-hosted webapi method exposed in the external process to start a job there.

The problem here I want to get a notification when the job was completed to notify user it's ready if he's still browsing our web-site (planning to use SignalR here). If it wasn't hosted in the external process it would be obvious.

But what's the best approach to get notified when it's hosted in the external process? Is exposing a web-method in the web application for external process to call after completion is a proper way?

We're currently planning using Quartz.NET for processing external jobs but don't mind trying some other things like Hangfire.


Solution

  • Sorry it wasn't clear to me if the external process is owned by a third party system or it's yours.

    In case it is a third party a web hook is a good and simple solution. You can define an endpoint which is called when the external process finishes.

    Otherwise I would suggest using a messaging system to communicate both services. Just send a message to the external process to initiate the export, and send another message from the external process when the job is finished. This way you ensure that if one service is down at the moment of the notification the message will be sent and processed as soon as the service goes up again.