AO.BackgroundJobs

Abstract base class for managing long-running background jobs, such as from Azure Functions


Keywords
License
MIT
Install
Install-Package AO.BackgroundJobs -Version 1.0.2

Documentation

Nuget

This is a framework for working with QueueTrigger Azure Functions to provide highly scaleable background processing along with a comprehensive end-user notification feature, intended for Blazor.

  • At the heart of this is an abstract class BackgroundJobBase you'd use to implement the body of your Azure Function with a queue trigger. Here's a sample from the test project. See also this more realistic zip file builder example. As an abstract class, there a couple methods you need to implement: OnExecuteAsync and OnStatusUpdatedAsync. The public method you call in your Azure Function is ExecuteAsync

  • One of BackgroundJobBase's dependencies is JobRepositoryBase. This is what enables the BackgroundJobBase to get job info and update the status of jobs in a database or wherever you're tracking job info.

  • The BackgroundJobInfo model class is intended to be created as a database table. This is where this happens in a test. This is abstract so you have to create your own table with a specific TKey type, as in this example.

  • There are a couple extension methods, most importantly QueueJobAsync which you'd use from your client applications. This bundles the Azure Queue message send with storing the job info that is subsequently tracked.

On the client side, there are some pieces coming together that handle state change events and display in a Blazor app. This stuff is not working yet:

  • Application has a singleton JobTracker repository, defined here. This is what provides access to the job request and result data, start and stop timestamp and failure info. This powers both an end-user notification view as well as an admin dashboard of job info, failures, and throughput info.

  • There is also a QueueManager, defined here which provides a single access point to all the available queues in an application. For example there is a ZipBuilder queue that an application can use to initiate a background job request.

  • I'm using an extremely rudimentary BackgroundJob component at the moment that will eventually resemble something typically seen in an application under a bell icon in the upper right, for example. This is what has a little loading spinner gif, and shows the duration and, eventually, output info about the job -- such as access to a download link or some other output.

  • The Blazor app must listen for job status changes, and it does so here, and then propagates this activity as an event, which the BackgroundJob component responds to. Within the event handler, the component triggers its own refresh.