public static void Patch(this BulkActionPushNotification target, BulkActionProgressContext source)
 {
     target.Description    = source.Description;
     target.Errors         = source.Errors;
     target.ProcessedCount = source.ProcessedCount;
     target.TotalCount     = source.TotalCount;
 }
Beispiel #2
0
        public async Task <ActionResult <BulkActionPushNotification> > Run([FromBody] BulkActionContext context)
        {
            ValidateContext(context);

            var actionProvider = _bulkActionProviderStorage.Get(context.ActionName);

            if (!await IsAuthorizedUserHasPermissionsAsync(actionProvider.Permissions))
            {
                return(Unauthorized());
            }

            var creator      = _userNameResolver.GetCurrentUserName();
            var notification = new BulkActionPushNotification(creator)
            {
                Title       = $"{context.ActionName}",
                Description = "Starting…"
            };

            notification.JobId = _backgroundJobExecutor.Enqueue <BulkActionJob>(job => job.ExecuteAsync(context, notification, JobCancellationToken.Null, null));

            return(Ok(notification));
        }
Beispiel #3
0
        public async Task ExecuteAsync(
            BulkActionContext bulkActionContext,
            BulkActionPushNotification notification,
            IJobCancellationToken cancellationToken,
            PerformContext performContext)
        {
            Validate(bulkActionContext);
            Validate(performContext);

            try
            {
                var tokenWrapper = new JobCancellationTokenWrapper(cancellationToken);
                await _bulkActionExecutor.ExecuteAsync(
                    bulkActionContext,
                    context =>
                {
                    notification.Patch(context);
                    notification.JobId = performContext.BackgroundJob.Id;
                    _pushNotificationManager.Send(notification);
                },
                    tokenWrapper);
            }
            catch (JobAbortedException)
            {
                // idle
            }
            catch (Exception exception)
            {
                notification.Errors.Add(exception.ExpandExceptionMessage());
            }
            finally
            {
                notification.Description = "Job finished";
                notification.Finished    = DateTime.UtcNow;
                _pushNotificationManager.Send(notification);
            }
        }