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
Scott Reed
August 13, 2020 — 6:37 pm
There is a plug called scheduled job overview that gives overview in a grid of the scheduled jobs as well as graphical performance breakdown.
zanganeh
August 16, 2020 — 10:34 pm
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