This commit is contained in:
Hamid Reza Mohammadi 2023-07-30 10:53:20 +03:30
parent 4358c272eb
commit 9301b02936
5 changed files with 30 additions and 17 deletions

View File

@ -49,7 +49,7 @@ namespace RMuseum.Controllers
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public async Task<IActionResult> ProcessQueueAsync()
{
var res = await _ftpService.ProcessQueueAsync();
var res = await _ftpService.ProcessQueueAsync(null);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
return Ok();

View File

@ -18573,19 +18573,21 @@
Queued FTP Upload Service Implementation
</summary>
</member>
<member name="M:RMuseum.Services.Implementation.QueuedFTPUploadService.AddAsync(System.String,System.String,System.Boolean)">
<member name="M:RMuseum.Services.Implementation.QueuedFTPUploadService.AddAsync(RMuseum.DbContext.RMuseumDbContext,System.String,System.String,System.Boolean)">
<summary>
add upload (you should call ProcessQueue manually)
</summary>
<param name="context">s</param>
<param name="localFilePath"></param>
<param name="remoteFilePath"></param>
<param name="deleteFileAfterUpload"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.QueuedFTPUploadService.ProcessQueueAsync">
<member name="M:RMuseum.Services.Implementation.QueuedFTPUploadService.ProcessQueueAsync(RMuseum.DbContext.RMuseumDbContext)">
<summary>
process queue
</summary>
<param name="callContext"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.QueuedFTPUploadService.ResetQueueAsync">
@ -19625,19 +19627,21 @@
Queued FTP Upload Service
</summary>
</member>
<member name="M:RMuseum.Services.IQueuedFTPUploadService.AddAsync(System.String,System.String,System.Boolean)">
<member name="M:RMuseum.Services.IQueuedFTPUploadService.AddAsync(RMuseum.DbContext.RMuseumDbContext,System.String,System.String,System.Boolean)">
<summary>
add upload (you should call ProcessQueue manually)
</summary>
<param name="context">s</param>
<param name="localFilePath"></param>
<param name="remoteFilePath"></param>
<param name="deleteFileAfterUpload"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IQueuedFTPUploadService.ProcessQueueAsync">
<member name="M:RMuseum.Services.IQueuedFTPUploadService.ProcessQueueAsync(RMuseum.DbContext.RMuseumDbContext)">
<summary>
process queue
</summary>
<param name="callContext"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IQueuedFTPUploadService.ResetQueueAsync">

View File

@ -1,4 +1,5 @@
using RMuseum.Models.ExternalFTPUpload;
using RMuseum.DbContext;
using RMuseum.Models.ExternalFTPUpload;
using RSecurityBackend.Models.Generic;
using System.Threading.Tasks;
@ -12,17 +13,19 @@ namespace RMuseum.Services
/// <summary>
/// add upload (you should call ProcessQueue manually)
/// </summary>
/// <param name="context">s</param>
/// <param name="localFilePath"></param>
/// <param name="remoteFilePath"></param>
/// <param name="deleteFileAfterUpload"></param>
/// <returns></returns>
Task<RServiceResult<QueuedFTPUpload>> AddAsync(string localFilePath, string remoteFilePath, bool deleteFileAfterUpload);
Task<RServiceResult<QueuedFTPUpload>> AddAsync(RMuseumDbContext context, string localFilePath, string remoteFilePath, bool deleteFileAfterUpload);
/// <summary>
/// process queue
/// </summary>
/// <param name="callContext"></param>
/// <returns></returns>
Task<RServiceResult<bool>> ProcessQueueAsync();
Task<RServiceResult<bool>> ProcessQueueAsync(RMuseumDbContext callContext);
/// <summary>
/// reset queue

View File

@ -457,7 +457,7 @@ namespace RMuseum.Services.Implementation
var remotePDFFilePath = $"{Configuration.GetSection("ExternalFTPServer")["RootPath"]}/pdf/{book.StorageFolderName}/{Path.GetFileName(localPDFFilePath)}";
if (!skipUpload)
{
var res = await _ftpService.AddAsync(localPDFFilePath, remotePDFFilePath, true);
var res = await _ftpService.AddAsync(context, localPDFFilePath, remotePDFFilePath, true);
if(!string.IsNullOrEmpty(res.ExceptionString))
{
return new RServiceResult<bool>(false, $"ftp {localPDFFilePath} => {remotePDFFilePath} {res.ExceptionString}");
@ -467,7 +467,7 @@ namespace RMuseum.Services.Implementation
var remoteCoverImageFilePath = $"{Configuration.GetSection("ExternalFTPServer")["RootPath"]}/pdf/{book.StorageFolderName}/{Path.GetFileName(localCoverImageFilePath)}";
if (!skipUpload)
{
var res = await _ftpService.AddAsync(localCoverImageFilePath, remoteCoverImageFilePath, true);
var res = await _ftpService.AddAsync(context, localCoverImageFilePath, remoteCoverImageFilePath, true);
if (!string.IsNullOrEmpty(res.ExceptionString))
{
return new RServiceResult<bool>(false, $"ftp {localCoverImageFilePath} => {remoteCoverImageFilePath} {res.ExceptionString}");
@ -484,7 +484,7 @@ namespace RMuseum.Services.Implementation
if (!skipUpload)
{
var remoteFilePath = $"{Configuration.GetSection("ExternalFTPServer")["RootPath"]}/pdf/{book.CoverImage.FolderName}/{Path.GetFileName(localFilePath)}";
var res = await _ftpService.AddAsync(localFilePath, remoteFilePath, true);
var res = await _ftpService.AddAsync(context, localFilePath, remoteFilePath, true);
if (!string.IsNullOrEmpty(res.ExceptionString))
{
return new RServiceResult<bool>(false, $"ftp {localFilePath} => {remoteFilePath} {res.ExceptionString}");
@ -495,7 +495,7 @@ namespace RMuseum.Services.Implementation
{
if(false == await context.QueuedFTPUploads.AsNoTracking().Where(p => p.Processing).AnyAsync())
{
var res = await _ftpService.ProcessQueueAsync();
var res = await _ftpService.ProcessQueueAsync(context);
if (!string.IsNullOrEmpty(res.ExceptionString))
{
return new RServiceResult<bool>(false, $"FTP ProcessQueueAsync : {res.ExceptionString}");

View File

@ -22,11 +22,12 @@ namespace RMuseum.Services.Implementation
/// <summary>
/// add upload (you should call ProcessQueue manually)
/// </summary>
/// <param name="context">s</param>
/// <param name="localFilePath"></param>
/// <param name="remoteFilePath"></param>
/// <param name="deleteFileAfterUpload"></param>
/// <returns></returns>
public async Task<RServiceResult<QueuedFTPUpload>> AddAsync(string localFilePath, string remoteFilePath, bool deleteFileAfterUpload)
public async Task<RServiceResult<QueuedFTPUpload>> AddAsync(RMuseumDbContext context, string localFilePath, string remoteFilePath, bool deleteFileAfterUpload)
{
try
{
@ -38,8 +39,8 @@ namespace RMuseum.Services.Implementation
QueueDate = DateTime.Now,
Processing = false,
};
_context.QueuedFTPUploads.Add(q);
await _context.SaveChangesAsync();
context.QueuedFTPUploads.Add(q);
await context.SaveChangesAsync();
return new RServiceResult<QueuedFTPUpload>(q);
}
catch (Exception exp)
@ -51,12 +52,17 @@ namespace RMuseum.Services.Implementation
/// <summary>
/// process queue
/// </summary>
/// <param name="callContext"></param>
/// <returns></returns>
public async Task<RServiceResult<bool>> ProcessQueueAsync()
public async Task<RServiceResult<bool>> ProcessQueueAsync(RMuseumDbContext callContext)
{
try
{
var processing = await _context.QueuedFTPUploads.AsNoTracking().Where(q => q.Processing).FirstOrDefaultAsync();
if(callContext == null)
{
callContext = _context;
}
var processing = await callContext.QueuedFTPUploads.AsNoTracking().Where(q => q.Processing).FirstOrDefaultAsync();
if(processing != null)
{
return new RServiceResult<bool>(false, $"already processing {processing.Id}.");