Skip to content

Commit

Permalink
Merge pull request #25 from VirtoCommerce/feat/VCPS-push-description
Browse files Browse the repository at this point in the history
feat: Align push notification description with platform defaults
  • Loading branch information
vladimir-buravlev committed Jun 21, 2024
2 parents fd55af6 + 9d0b7c6 commit af1086d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ void ErrorCallback(ErrorInfo info)
ErrorLine = context.ProgressInfo?.ProcessedCount,
ErrorMessage = ex.ExpandExceptionMessage(),
});
throw;
}
finally
{
Expand All @@ -142,7 +141,7 @@ void ErrorCallback(ErrorInfo info)
importRemainingEstimator.Stop(context);

// Import finished
importProgress.Description = "Import has been finished";
importProgress.Description = $"Import completed {(importProgress.Errors?.Count > 0 ? "with errors" : "successfully")}";
importProgress.Finished = DateTime.UtcNow;
importProgress.ReportUrl = errorReportResult ?? importProgress.ReportUrl;

Expand Down
21 changes: 16 additions & 5 deletions src/VirtoCommerce.ImportModule.Data/Services/ImportRunService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public ImportPushNotification RunImportBackgroundJob(ImportProfile importProfile
{
var pushNotification = new ImportPushNotification(_userNameResolver.GetCurrentUserName())
{
Title = "Import process",
ProfileId = importProfile.Id,
ProfileName = importProfile.Name,
};
Expand Down Expand Up @@ -105,7 +106,7 @@ public async Task<ImportPushNotification> RunImportAsync(ImportProfile importPro

async Task ProgressInfoCallback(ImportProgressInfo progressInfo)
{
pushNotification.Title = progressInfo.Description;
pushNotification.Description = progressInfo.Description;

pushNotification.EstimatingRemaining = progressInfo.EstimatingRemaining;
pushNotification.EstimatedRemaining = progressInfo.EstimatedRemaining;
Expand All @@ -117,6 +118,13 @@ async Task ProgressInfoCallback(ImportProgressInfo progressInfo)
pushNotification.Errors = progressInfo.Errors;
pushNotification.ReportUrl = progressInfo.ReportUrl;

if (pushNotification.ProcessedCount > 0 && pushNotification.Finished is null)
{
pushNotification.Description = pushNotification.TotalCount > 0
? $"{pushNotification.ProcessedCount} of {pushNotification.TotalCount} have been imported"
: $"{pushNotification.ProcessedCount} have been imported";
}

await _pushNotificationManager.SendAsync(pushNotification);

importRunHistory.UpdateProgress(pushNotification);
Expand All @@ -126,24 +134,27 @@ async Task ProgressInfoCallback(ImportProgressInfo progressInfo)

try
{

await _importRunHistoryCrudService.SaveChangesAsync(new[] { importRunHistory });

await _dataImportManager.ImportAsync(importProfile, ProgressInfoCallback, cancellationToken);
}
catch (JobAbortedException)
{
pushNotification.Title = "Import was cancelled by user";
pushNotification.Description = "Import was cancelled by user";
}
catch (OperationCanceledException)
{
pushNotification.Description = "The operation was cancelled";
}
catch (Exception ex)
{
pushNotification.Errors.Add(ex.ToString());
pushNotification.Title = "Import failed";
pushNotification.Description = "Import failed";
throw;
}
finally
{
pushNotification.Finished = DateTime.UtcNow;
pushNotification.Finished ??= DateTime.UtcNow;

await _pushNotificationManager.SendAsync(pushNotification);

Expand Down

0 comments on commit af1086d

Please sign in to comment.