#20 retrypublish api
This commit is contained in:
parent
25472b208c
commit
985e8195ca
@ -250,6 +250,29 @@ namespace RMuseum.Controllers
|
|||||||
return BadRequest(res.ExceptionString);
|
return BadRequest(res.ExceptionString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// retry publish unpublished narrations
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get User Profiles
|
/// Get User Profiles
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -675,6 +675,12 @@
|
|||||||
</summary>
|
</summary>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:RMuseum.Controllers.AudioNarrationController.RetryPublish">
|
||||||
|
<summary>
|
||||||
|
retry publish unpublished narrations
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:RMuseum.Controllers.AudioNarrationController.GetUserNarrationProfiles">
|
<member name="M:RMuseum.Controllers.AudioNarrationController.GetUserNarrationProfiles">
|
||||||
<summary>
|
<summary>
|
||||||
Get User Profiles
|
Get User Profiles
|
||||||
@ -3736,6 +3742,11 @@
|
|||||||
<param name="userId">if userId is empty all user uploads would be returned</param>
|
<param name="userId">if userId is empty all user uploads would be returned</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:RMuseum.Services.IAudioNarrationService.RetryPublish">
|
||||||
|
<summary>
|
||||||
|
retry publish unpublished narrations
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="T:RMuseum.Services.Implementation.ArtifactService">
|
<member name="T:RMuseum.Services.Implementation.ArtifactService">
|
||||||
<summary>
|
<summary>
|
||||||
IArtifactService implementation
|
IArtifactService implementation
|
||||||
@ -4479,6 +4490,11 @@
|
|||||||
<param name="model"></param>
|
<param name="model"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:RMuseum.Services.Implementation.AudioNarrationService.RetryPublish">
|
||||||
|
<summary>
|
||||||
|
retry publish unpublished narrations
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="M:RMuseum.Services.Implementation.AudioNarrationService.GetUploadSession(System.Guid)">
|
<member name="M:RMuseum.Services.Implementation.AudioNarrationService.GetUploadSession(System.Guid)">
|
||||||
<summary>
|
<summary>
|
||||||
Get Upload Session (including files)
|
Get Upload Session (including files)
|
||||||
|
|||||||
@ -119,6 +119,9 @@ namespace RMuseum.Services
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<RServiceResult<(PaginationMetadata PagingMeta, dynamic[] Items)>> GetUploads(PagingParameterModel paging, Guid userId);
|
Task<RServiceResult<(PaginationMetadata PagingMeta, dynamic[] Items)>> GetUploads(PagingParameterModel paging, Guid userId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// retry publish unpublished narrations
|
||||||
|
/// </summary>
|
||||||
|
public void RetryPublish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,6 @@ using RMuseum.DbContext;
|
|||||||
using RMuseum.Models.GanjoorAudio;
|
using RMuseum.Models.GanjoorAudio;
|
||||||
using RMuseum.Models.GanjoorAudio.ViewModels;
|
using RMuseum.Models.GanjoorAudio.ViewModels;
|
||||||
using RMuseum.Models.UploadSession;
|
using RMuseum.Models.UploadSession;
|
||||||
using RMuseum.Services.Implementation.ImportedFromDesktopGanjoor;
|
|
||||||
using RSecurityBackend.Models.Generic;
|
using RSecurityBackend.Models.Generic;
|
||||||
using RSecurityBackend.Services.Implementation;
|
using RSecurityBackend.Services.Implementation;
|
||||||
using System;
|
using System;
|
||||||
@ -561,7 +560,10 @@ namespace RMuseum.Services.Implementation
|
|||||||
(
|
(
|
||||||
async token =>
|
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
|
using var client = new SftpClient
|
||||||
(
|
(
|
||||||
@ -619,12 +621,9 @@ namespace RMuseum.Services.Implementation
|
|||||||
await connection.ExecuteAsync(sql);
|
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);
|
||||||
narration.AudioSyncStatus = (int)AudioSyncStatus.SynchronizedOrRejected;
|
await context.SaveChangesAsync();
|
||||||
context.AudioFiles.Update(narration);
|
|
||||||
await context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
await _notificationService.PushNotification
|
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
|
//if an error occurs, narration.AudioSyncStatus is not updated and narration can be idetified later to do "retrypublish" attempts
|
||||||
await _notificationService.PushNotification
|
//a logging solution should be put to work here to find out what is gone wrong
|
||||||
(
|
|
||||||
narration.OwnerId,
|
|
||||||
"خطا در پردازش نهایی",
|
|
||||||
$"{exp}{Environment.NewLine}" +
|
|
||||||
$"میتوانید با مراجعه به این صفحه TODO: client url وضعیت آن را بررسی کنید."
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -653,6 +646,26 @@ namespace RMuseum.Services.Implementation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// retry publish unpublished narrations
|
||||||
|
/// </summary>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get Upload Session (including files)
|
/// Get Upload Session (including files)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user