#418 StartExtractingQuotedPoems
This commit is contained in:
parent
0b3d160431
commit
145b60643e
@ -17309,7 +17309,13 @@
|
||||
<param name="metre"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.ParseRelatedPageAsync(RMuseum.DbContext.RMuseumDbContext,System.Int32)">
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.StartExtractingQuotedPoems">
|
||||
<summary>
|
||||
extracting quoted poems
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService._ParseRelatedPageAsync(RMuseum.DbContext.RMuseumDbContext,System.Int32)">
|
||||
<summary>
|
||||
parse related pages
|
||||
</summary>
|
||||
|
||||
@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using RMuseum.DbContext;
|
||||
using RMuseum.Models.Ganjoor;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using RSecurityBackend.Services.Implementation;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@ -14,13 +15,54 @@ namespace RMuseum.Services.Implementation
|
||||
/// </summary>
|
||||
public partial class GanjoorService : IGanjoorService
|
||||
{
|
||||
/// <summary>
|
||||
/// extracting quoted poems
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public RServiceResult<bool> StartExtractingQuotedPoems()
|
||||
{
|
||||
try
|
||||
{
|
||||
_backgroundTaskQueue.QueueBackgroundWorkItem
|
||||
(
|
||||
async token =>
|
||||
{
|
||||
using (RMuseumDbContext context = new RMuseumDbContext(new DbContextOptions<RMuseumDbContext>())) //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("StartExtractingQuotedPoems", "Query data")).Result;
|
||||
|
||||
var pages = await context.GanjoorPages.AsNoTracking().Where(p => p.SecondPoetId != null).ToListAsync();
|
||||
foreach (var page in pages)
|
||||
{
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 0, page.FullTitle);
|
||||
var res = await _ParseRelatedPageAsync(context, page.Id);
|
||||
if(string.IsNullOrEmpty(res.ExceptionString))
|
||||
{
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, page.FullTitle, false, res.ExceptionString);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
|
||||
}
|
||||
});
|
||||
return new RServiceResult<bool>(true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<bool>(false, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// parse related pages
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="pageId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<bool>> ParseRelatedPageAsync(RMuseumDbContext context, int pageId)
|
||||
private async Task<RServiceResult<bool>> _ParseRelatedPageAsync(RMuseumDbContext context, int pageId)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user