diff --git a/RMuseum/Controllers/AudioNarrationController.cs b/RMuseum/Controllers/AudioNarrationController.cs
index 21c1bcd1..4bd999e6 100644
--- a/RMuseum/Controllers/AudioNarrationController.cs
+++ b/RMuseum/Controllers/AudioNarrationController.cs
@@ -250,6 +250,29 @@ namespace RMuseum.Controllers
return BadRequest(res.ExceptionString);
}
+ ///
+ /// retry publish unpublished narrations
+ ///
+ ///
+ [HttpPost]
+ [Route("retrypublish")]
+ [Authorize(Policy = RMuseumSecurableItem.AudioNarrationEntityShortName + ":" + RMuseumSecurableItem.ModerateOperationShortName)]
+ [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))]
+ [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
+ public IActionResult RetryPublish()
+ {
+ try
+ {
+ _audioService.RetryPublish();
+ return Ok();
+ }
+ catch(Exception exp)
+ {
+ return BadRequest(exp.ToString());
+ }
+
+ }
+
///
/// Get User Profiles
///
diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml
index 1b97784f..54f02dc3 100644
--- a/RMuseum/RMuseum.xml
+++ b/RMuseum/RMuseum.xml
@@ -675,6 +675,12 @@
+
+
+ retry publish unpublished narrations
+
+
+
Get User Profiles
@@ -3736,6 +3742,11 @@
if userId is empty all user uploads would be returned
+
+
+ retry publish unpublished narrations
+
+
IArtifactService implementation
@@ -4479,6 +4490,11 @@
+
+
+ retry publish unpublished narrations
+
+
Get Upload Session (including files)
diff --git a/RMuseum/Services/IAudioNarrationService.cs b/RMuseum/Services/IAudioNarrationService.cs
index 429a428b..b6c82451 100644
--- a/RMuseum/Services/IAudioNarrationService.cs
+++ b/RMuseum/Services/IAudioNarrationService.cs
@@ -119,6 +119,9 @@ namespace RMuseum.Services
///
Task> GetUploads(PagingParameterModel paging, Guid userId);
-
+ ///
+ /// retry publish unpublished narrations
+ ///
+ public void RetryPublish();
}
}
diff --git a/RMuseum/Services/Implementation/AudioNarrationService.cs b/RMuseum/Services/Implementation/AudioNarrationService.cs
index 442ae031..3809725a 100644
--- a/RMuseum/Services/Implementation/AudioNarrationService.cs
+++ b/RMuseum/Services/Implementation/AudioNarrationService.cs
@@ -9,7 +9,6 @@ using RMuseum.DbContext;
using RMuseum.Models.GanjoorAudio;
using RMuseum.Models.GanjoorAudio.ViewModels;
using RMuseum.Models.UploadSession;
-using RMuseum.Services.Implementation.ImportedFromDesktopGanjoor;
using RSecurityBackend.Models.Generic;
using RSecurityBackend.Services.Implementation;
using System;
@@ -561,7 +560,10 @@ namespace RMuseum.Services.Implementation
(
async token =>
{
- await _PublishNarration(narration);
+ using (RMuseumDbContext context = new RMuseumDbContext(Configuration)) //this is long running job, so _context might be already been freed/collected by GC
+ {
+ await _PublishNarration(narration, context);
+ }
});
}
@@ -576,7 +578,7 @@ namespace RMuseum.Services.Implementation
}
}
- private async Task _PublishNarration(PoemNarration narration)
+ private async Task _PublishNarration(PoemNarration narration, RMuseumDbContext context)
{
using var client = new SftpClient
(
@@ -619,12 +621,9 @@ namespace RMuseum.Services.Implementation
await connection.ExecuteAsync(sql);
}
- using (RMuseumDbContext context = new RMuseumDbContext(Configuration)) //this is long running job, so _context might be already been freed/collected by GC
- {
- narration.AudioSyncStatus = (int)AudioSyncStatus.SynchronizedOrRejected;
- context.AudioFiles.Update(narration);
- await context.SaveChangesAsync();
- }
+ narration.AudioSyncStatus = (int)AudioSyncStatus.SynchronizedOrRejected;
+ context.AudioFiles.Update(narration);
+ await context.SaveChangesAsync();
await _notificationService.PushNotification
(
@@ -636,16 +635,10 @@ namespace RMuseum.Services.Implementation
}
- catch (Exception exp)
+ catch
{
- //if an error occurs, narration.AudioSyncStatus is not updated and narration can be idetified later to do "retry" attempts
- await _notificationService.PushNotification
- (
- narration.OwnerId,
- "خطا در پردازش نهایی",
- $"{exp}{Environment.NewLine}" +
- $"میتوانید با مراجعه به این صفحه TODO: client url وضعیت آن را بررسی کنید."
- );
+ //if an error occurs, narration.AudioSyncStatus is not updated and narration can be idetified later to do "retrypublish" attempts
+ //a logging solution should be put to work here to find out what is gone wrong
}
finally
{
@@ -653,6 +646,26 @@ namespace RMuseum.Services.Implementation
}
}
+ ///
+ /// retry publish unpublished narrations
+ ///
+ public void RetryPublish()
+ {
+ _backgroundTaskQueue.QueueBackgroundWorkItem
+ (
+ async token =>
+ {
+ using (RMuseumDbContext context = new RMuseumDbContext(Configuration)) //this is long running job, so _context might be already been freed/collected by GC
+ {
+ var list = await context.AudioFiles.Where(a => a.ReviewStatus == AudioReviewStatus.Approved && a.AudioSyncStatus != (int)AudioSyncStatus.SynchronizedOrRejected).ToListAsync();
+ foreach (PoemNarration narration in list)
+ {
+ await _PublishNarration(narration, context);
+ }
+ }
+ });
+ }
+
///
/// Get Upload Session (including files)