public async Task ImportBackgroundAsync(ImportDataRequest request, ImportPushNotification pushNotification, IJobCancellationToken jobCancellationToken, PerformContext context) { ValidateParameters(request, pushNotification); try { var importer = _customerDataImporters.First(x => x.MemberType == request.MemberType); await importer.ImportAsync(request, progressInfo => ProgressCallback(progressInfo, pushNotification, context), new JobCancellationTokenWrapper(jobCancellationToken)); } catch (JobAbortedException) { // job is aborted, do nothing } catch (Exception ex) { pushNotification.Errors.Add(ex.ExpandExceptionMessage()); } finally { pushNotification.Description = "Import finished"; pushNotification.Finished = DateTime.UtcNow; await _pushNotificationManager.SendAsync(pushNotification); } }
private static void ValidateParameters(ImportPushNotification pushNotification) { if (pushNotification == null) { throw new ArgumentNullException(nameof(pushNotification)); } }
public static void Patch(this ImportPushNotification target, ImportProgressInfo source) { target.Description = source.Description; target.ProcessedCount = source.ProcessedCount; target.TotalCount = source.TotalCount; target.ContactsCreated = source.ContactsCreated; target.ContactsUpdated = source.ContactsUpdated; target.ErrorCount = source.ErrorCount; target.Errors = source.Errors; target.ReportUrl = source.ReportUrl; }
public async Task <ActionResult <ImportPushNotification> > RunImport([FromBody] ImportDataRequest request) { var notification = new ImportPushNotification(_userNameResolver.GetCurrentUserName()) { Title = "Prices import", Description = "Starting import task..." }; await _pushNotificationManager.SendAsync(notification); notification.JobId = BackgroundJob.Enqueue <ImportJob>(importJob => importJob.ImportBackgroundAsync(request, notification, JobCancellationToken.Null, null)); return(Ok(notification)); }
private void ValidateParameters(ImportDataRequest request, ImportPushNotification pushNotification) { if (pushNotification == null) { throw new ArgumentNullException(nameof(pushNotification)); } var importer = _customerDataImporters.FirstOrDefault(x => x.MemberType == request.MemberType); if (importer == null) { throw new ArgumentException($"Not allowed argument value in field {nameof(request.MemberType)}", nameof(request)); } }
private void ProgressCallback(ImportProgressInfo x, ImportPushNotification pushNotification, PerformContext context) { pushNotification.Patch(x); pushNotification.JobId = context.BackgroundJob.Id; _pushNotificationManager.Send(pushNotification); }