Our customer asked for a custom dashboard that shows uses data sources, including ‘Schedule Job’ history. To achieve this we are going to use:

IScheduledJobRepository

And implementation would be quite easy:

[HttpPost]
public async Task<ActionResult> ImportHistory()
{
    var importUsersJobType = typeof(ImportUsersJob);

    var job = scheduledJobRepository
        .List()
        .FirstOrDefault(j => j.TypeName == $"{importUsersJobType.Namespace}.{importUsersJobType.Name}");

    var result = await scheduledJobLogRepository.GetAsync(job.ID, 0, int.MaxValue);

    return Json(result.PagedResult.Select(a => new
    {
        CompletedUtc = a.CompletedUtc.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"),
        a.Message,
        Status = a.Status.ToString()
    }));
}

The schedule job type is ‘ImportUserJob’, and we are getting history data of the execution of the job:

var result = await scheduledJobLogRepository.GetAsync(job.ID, 0, int.MaxValue);

And finally return back JSON object of exection data back to FED:

return Json(result.PagedResult.Select(a => new
    {
        CompletedUtc = a.CompletedUtc.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"),
        a.Message,
        Status = a.Status.ToString()
    }));

PS: Scott Reed mentioned there is a plugin to overview all of your scheduled jobs please find it here

2 thoughts on “Custom page for schedule job status

  1. There is a plug called scheduled job overview that gives overview in a grid of the scheduled jobs as well as graphical performance breakdown.

    1. Really appreciate it @Scott. I’ve been asked about IScheduledJobLogRepository and how it works and it is more to clarify that but for sure that is out of box solution. I added a link to the post as well for anyone is interested

Leave a Reply

Your email address will not be published. Required fields are marked *