From 3189d542660faf489a4785c83409034e9b2a78e2 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 26 Jun 2020 20:19:25 +0000 Subject: [PATCH] --- .../Controllers/AttachmentController.cs | 92 ++++++------------- server/AyaNova/biz/AttachmentBiz.cs | 7 +- server/AyaNova/util/FileUtil.cs | 3 +- 3 files changed, 34 insertions(+), 68 deletions(-) diff --git a/server/AyaNova/Controllers/AttachmentController.cs b/server/AyaNova/Controllers/AttachmentController.cs index 964e1ddd..c6757f16 100644 --- a/server/AyaNova/Controllers/AttachmentController.cs +++ b/server/AyaNova/Controllers/AttachmentController.cs @@ -498,71 +498,35 @@ namespace AyaNova.Api.Controllers return v; } + + + /// + /// Trigger immediate AttachmentMaintenanceJob + /// + /// + /// Job Id + [HttpPost("maintenance")] + [Authorize] + public async Task PostTriggerAttachmentMaintenanceJob() + { + if (serverState.IsClosed) + return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); + if (!Authorized.HasModifyRole(HttpContext.Items, AyaType.FileAttachment)) + return StatusCode(403, new ApiNotAuthorizedResponse()); + var JobName = $"Attachment maintenance (demand)"; + OpsJob j = new OpsJob(); + j.Name = JobName; + j.ObjectType = AyaType.FileAttachment; + j.JobType = JobType.AttachmentMaintenance; + j.SubType = JobSubType.NotSet; + j.Exclusive = true; + await JobsBiz.AddJobAsync(j); + await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.ServerJob, AyaEvent.Created, JobName), ct); + return Accepted(new { JobId = j.GId }); + } + + }//eoc }//eons -#region sample html form to work with this -/* - - - - - - - - - - - -
- - - - - - - -
- - - - - - */ -#endregion \ No newline at end of file diff --git a/server/AyaNova/biz/AttachmentBiz.cs b/server/AyaNova/biz/AttachmentBiz.cs index cd618863..76a8c123 100644 --- a/server/AyaNova/biz/AttachmentBiz.cs +++ b/server/AyaNova/biz/AttachmentBiz.cs @@ -64,6 +64,9 @@ namespace AyaNova.Biz await JobsBiz.LogJobAsync(job.GId, $"Starting..."); apiServerState.SetOpsOnly("Attachment file maintenance"); + + + // EXISTENCE CHECK //iterate all records in chunks bool moreRecords = true; @@ -93,9 +96,9 @@ namespace AyaNova.Biz } } while (moreRecords); - // long totalRecs = await ct.FileAttachment.LongCountAsync(); - + // long totalRecs = await ct.FileAttachment.LongCountAsync(); + var allAttachments = FileUtil.GetAllAttachmentFilePaths(); // iterate FileAttachment records, if physically present then flag as such // make sure it has a short circuit that if there are NO files physically then all are out of sync diff --git a/server/AyaNova/util/FileUtil.cs b/server/AyaNova/util/FileUtil.cs index 6d56e69c..9748f953 100644 --- a/server/AyaNova/util/FileUtil.cs +++ b/server/AyaNova/util/FileUtil.cs @@ -512,8 +512,7 @@ namespace AyaNova.Util /// /// Confirm if a file exists in the attachment folder /// - /// name of attachment file - /// duh! + /// name of attachment file internal static bool AttachmentFileExists(string fileName) { if (string.IsNullOrWhiteSpace(fileName))