private async Task TryExecuteAsync(IWidget widget) { try { var request = widget switch { IMetricWidget => MetricRequestFactory.Create((dynamic)widget), IStatusWidget => StatusRequestFactory.Create((dynamic)widget), _ => throw new NotSupportedException(widget.GetType().FullName + " is not supported by the job scheduler"), }; await _mediator.Send(request); } catch (Exception ex) { _logger.LogError(ex, "An error occurred while executing job for widget '{widget}'", widget.Name); } }
public virtual async Task Execute(IJobExecutionContext context) { try { if (context.JobDetail.JobDataMap.ContainsKey(nameof(IWidget)) && context.JobDetail.JobDataMap[nameof(IWidget)] is IWidget widget && widget.IsEnabled) { var request = widget switch { IMetricWidget _ => MetricRequestFactory.Create((dynamic)widget), IStatusWidget _ => StatusRequestFactory.Create((dynamic)widget), _ => throw new NotSupportedException($"{widget?.GetType().FullName} is not supported by the job scheduler."), }; await _mediator.Send(request).ConfigureAwait(false); } else { _logger.LogError("An error occurred while executing job. Widget not found in job context."); } }