From 5da8dda866e850bdb866eeca9af7ecaf2546d8ea Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Fri, 17 Dec 2021 11:54:02 +0330 Subject: [PATCH] #262 skeleton for the method to batch convert museum images to webp --- RMuseum/RMuseum.xml | 9 ++++ .../ArtifactService-ConvertToWebp.cs | 44 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 RMuseum/Services/Implementation/ArtifactService-Partials/ArtifactService-ConvertToWebp.cs diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 21782c57..d5bee6c8 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -9933,6 +9933,15 @@ IArtifactService implementation + + IArtifactService implementation + + + + + convert original images to webp + + diff --git a/RMuseum/Services/Implementation/ArtifactService-Partials/ArtifactService-ConvertToWebp.cs b/RMuseum/Services/Implementation/ArtifactService-Partials/ArtifactService-ConvertToWebp.cs new file mode 100644 index 00000000..2978e1c5 --- /dev/null +++ b/RMuseum/Services/Implementation/ArtifactService-Partials/ArtifactService-ConvertToWebp.cs @@ -0,0 +1,44 @@ +using Microsoft.EntityFrameworkCore; +using RMuseum.DbContext; +using RSecurityBackend.Models.Generic; +using RSecurityBackend.Services.Implementation; +using System; + +namespace RMuseum.Services.Implementation +{ + + /// + /// IArtifactService implementation + /// + public partial class ArtifactService : IArtifactService + { + /// + /// convert original images to webp + /// + /// + public RServiceResult StartConvertingOriginalImagesToWebp() + { + _backgroundTaskQueue.QueueBackgroundWorkItem + ( + async token => + { + using (RMuseumDbContext context = new RMuseumDbContext(new DbContextOptions())) //this is long running job, so _context might be already been freed/collected by GC + { + LongRunningJobProgressServiceEF jobProgressServiceEF = new LongRunningJobProgressServiceEF(context); + var job = (await jobProgressServiceEF.NewJob($"Converting Original Images To Webp", "Query data")).Result; + try + { + await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true); + } + catch (Exception exp) + { + await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, exp.ToString()); + } + + } + }); + + return new RServiceResult(true); + } + } +} \ No newline at end of file