Esempio n. 1
0
        public async Task <IActionResult> Index()
        {
            _logger.LogInformation("Enqueuing a job and having it execute after 5 secs.");
            await _jobs.EnqueueAsync <FooService>(
                fooService => fooService.LogSomething("Executing after a delay."),
                TimeSpan.FromSeconds(5));

            return(View());
        }
        public IActionResult RunTestJob()
        {
            var processId = Guid.NewGuid().ToString();

            _jobs.EnqueueAsync <DbLogService>(
                service => service.SetCategory("Jobs", processId).LogAsync("Executed Test Job @ " + DateTime.Now.ToString("hh:mm:ss.fffff"))
                );

            return(Ok(processId));
        }
Esempio n. 3
0
        private async Task <FileDocument> DownloadItemsAsJobAsync(string ownerId, IFolder targetFolder, IFolder[] folders, FileDocument[] documents)
        {
            Ensure.NotNullOrEmpty(ownerId, $"");

            // Choose a guid for the zipped output file name
            // NOPE! The Guid should be the documentID for the zip file you just created.
            var result = await CreateZipDocumentAsync(targetFolder, folders, documents);

            await _documentService.CreateAsync(result);

            await _folderManager.AddDocumentAsync(result, targetFolder);

            await _log.LogEventCreateAsync(result, ownerId);

            // So, I need to create the DB document record (and GUID) immediately. When the JobZip finishes, *it* needs to push
            // that data onto the file system!
            // Documents have their own folder information and are thus self-referencing, which the JobsScheduler (JSON) cannot handle
            // This is more minimalist data, but as the job is async, the extra CPU time to perform lookups is OK here.
            var tf  = targetFolder.ToFolder();
            var kvs = GetFlatDocuments(folders).Concat(documents.Select(x => new DocumentFolderEntry(tf, x)))
                      .ToDictionary(document => $"{_folderManager.GetPathAsync(document.Folder).Result}/{document.Document.FileName}",
                                    document => document.Document.DocumentId)
                      .ToArray();

            // NOTE: Do *not* await this, as the whole point is to run this action asynchronously
            _jobs.EnqueueAsync(() => new JobZip(this, _documentService, _uploadService, _libraryZipService, _folderManager)
                               .Execute(result, ownerId, targetFolder.Id, kvs));


            // Return the guid to the view
            return(result);
        }
        public async Task <ActionResult> SaveNotification(NotificationDetailsViewModel model)
        {
            //ModelState.AddModelError("EmailSubject", "Test Error.");

            if (ModelState.IsValid)
            {
                model.Title = BuildNotificationTitle(model);

                if (model.ScheduleAction == NotificationDetailsViewModel.ScheduleActions.Draft)
                {
                    model.Status = NotificationStatus.Draft;
                }
                else if (model.ScheduleAction == NotificationDetailsViewModel.ScheduleActions.SendNow)
                {
                    model.Status      = NotificationStatus.Scheduled;
                    model.TimeZoneId  = TimeZoneHelper.DefaultTimeZoneId; // TO DO: Get the time zone from the user context.
                    model.ScheduledDT = TimeZoneHelper.Now(model.TimeZoneId);
                }
                else
                {
                    model.Status = NotificationStatus.Scheduled;
                }

                var userGroupIds = new List <string>();
                userGroupIds.AddRange(model.NotificationGroupIds);
                userGroupIds.AddRange(model.ConnectionGroupIds);

                if (string.IsNullOrEmpty(model.Id))
                {
                    model.Id         = Guid.NewGuid().ToString("N");
                    model.CreatedUTC = DateTime.UtcNow;
                    model.CreatedBy  = User.GetUserId();
                    var insertNote = model.ProjectTo <Angelo.Connect.Models.Notification>();
                    await _notificationManager.InsertNotificationAsync(insertNote, userGroupIds);
                }
                else
                {
                    var updateNote = model.ProjectTo <Angelo.Connect.Models.Notification>();
                    await _notificationManager.UpdateNotificationAsync(updateNote, userGroupIds);
                }

                if (model.ScheduleAction == NotificationDetailsViewModel.ScheduleActions.SendNow)
                {
                    await _jobs.EnqueueAsync <NotificationProcessor>(proc => proc.ExecuteNotification(model.Id));

                    model.Status = NotificationStatus.Processing;
                }

                return(Ok(model));
            }
            return(BadRequest(ModelState));
        }
 public static Task EnqueueAsync <T>(this IJobsManager @this, Expression <Action <T> > methodCall, TimeSpan delay)
 {
     return(@this.EnqueueAsync(methodCall, DateTimeOffset.Now + delay));
 }