Example #1
0
        private async Task RunJob(IServiceScope scope, Type jobType, Dictionary <string, object> parameters)
        {
            var job       = (IJob)scope.ServiceProvider.GetService(jobType);
            var jobName   = jobType.Name;
            var mediator  = scope.ServiceProvider.GetService <IMediator>();
            var jobId     = Guid.NewGuid();
            var startTime = DateTime.UtcNow;

            try
            {
                await mediator.Execute(ReportJobState.GetRunning(jobId, jobName, startTime));

                _logger.LogInformation($"Executing '{jobName}'");
                var details = await job.Execute(parameters);

                await mediator.Execute(ReportJobState.GetSuccessful(jobId, jobName, startTime, DateTime.UtcNow, details));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Error while executing '{jobName}'");
                await mediator.Execute(ReportJobState.GetFailed(jobId, jobName, ex.Message, startTime, DateTime.UtcNow));
            }
        }
 public void ShouldThrowExceptionIfJobTypeIsEmpty([Values(null, "")] string jobType)
 {
     _handler.Awaiting(h => h.Handle(ReportJobState.GetSuccessful(Guid.NewGuid(), jobType, DateTime.UtcNow, DateTime.UtcNow, null)))
     .Should().Throw <ArgumentNullException>();
 }