mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 03:01:10 +00:00
Merge pull request #119 from BinaryAlley/refactor/fix-race-condition-chance-for-child-job-execution-in-library-scanning
Fixes a race condition chance for child job execution in library scanning module
This commit is contained in:
8 files changed
+18
-13
No files matched your search
@@ -6,7 +6,6 @@ using Lumina.Application.Common.Infrastructure.Authorization.Policies.Over18;
|
||||
using Lumina.Application.Common.Infrastructure.Security;
|
||||
using Lumina.Application.Common.Infrastructure.Time;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Progress;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Queue;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Cancellation;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Queue;
|
||||
@@ -19,6 +18,7 @@ using Lumina.Infrastructure.Core.MediaLibrary.Management.Scanning.Cancellation;
|
||||
using Lumina.Infrastructure.Core.MediaLibrary.Management.Scanning.Jobs.Common;
|
||||
using Lumina.Infrastructure.Core.MediaLibrary.Management.Scanning.Jobs.WrittenContent.Books;
|
||||
using Lumina.Infrastructure.Core.MediaLibrary.Management.Scanning.Progress;
|
||||
using Lumina.Infrastructure.Core.MediaLibrary.Management.Scanning.Queue;
|
||||
using Lumina.Infrastructure.Core.Security;
|
||||
using Lumina.Infrastructure.Core.Time;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
+3
-2
@@ -55,9 +55,10 @@ internal sealed class FileSystemDiscoveryJob : MediaLibraryScanJob, IFileSystemD
|
||||
{
|
||||
try
|
||||
{
|
||||
parentsPayloadsExecuted++; // increment the number of parents that finished their execution and called this job
|
||||
// increment the number of parents that finished their execution and called this job (beware race conditions, jobs run in parallel)
|
||||
int parentsCompleted = Interlocked.Increment(ref parentsPayloadsExecuted);
|
||||
// only execute this job's payload when it has no parents, or when all the parents finished their execution
|
||||
if (Parents.Count == 0 || parentsPayloadsExecuted == Parents.Count)
|
||||
if (Parents.Count == 0 || parentsCompleted == Parents.Count)
|
||||
{
|
||||
// this needs to be wrapped in a task because even though this job is processed in a "fire and forget" async manner, it still does synchronous
|
||||
// file system processing that takes time, and would block the processing of scan jobs in the in-memory queue
|
||||
|
||||
+3
-2
@@ -44,9 +44,10 @@ internal sealed class HashComparerJob : MediaLibraryScanJob, IHashComparerJob
|
||||
{
|
||||
try
|
||||
{
|
||||
parentsPayloadsExecuted++; // increment the number of parents that finished their execution and called this job
|
||||
// increment the number of parents that finished their execution and called this job (beware race conditions, jobs run in parallel)
|
||||
int parentsCompleted = Interlocked.Increment(ref parentsPayloadsExecuted);
|
||||
// only execute this job's payload when it has no parents, or when all the parents finished their execution
|
||||
if (Parents.Count == 0 || parentsPayloadsExecuted == Parents.Count)
|
||||
if (Parents.Count == 0 || parentsCompleted == Parents.Count)
|
||||
{
|
||||
Status = LibraryScanJobStatus.Running;
|
||||
Console.WriteLine("started file hashing");
|
||||
|
||||
+3
-2
@@ -43,9 +43,10 @@ internal sealed class RepositoryMetadataDiscoveryJob : MediaLibraryScanJob, IRep
|
||||
{
|
||||
try
|
||||
{
|
||||
parentsPayloadsExecuted++; // increment the number of parents that finished their execution and called this job
|
||||
// increment the number of parents that finished their execution and called this job (beware race conditions, jobs run in parallel)
|
||||
int parentsCompleted = Interlocked.Increment(ref parentsPayloadsExecuted);
|
||||
// only execute this job's payload when it has no parents, or when all the parents finished their execution
|
||||
if (Parents.Count == 0 || parentsPayloadsExecuted == Parents.Count)
|
||||
if (Parents.Count == 0 || parentsCompleted == Parents.Count)
|
||||
{
|
||||
// this needs to be wrapped in a task because even though this job is processed in a "fire and forget" async manner, it still does synchronous
|
||||
// file system processing that takes time, and would block the processing of scan jobs in the in-memory queue
|
||||
|
||||
+3
-2
@@ -43,9 +43,10 @@ internal sealed class RepositoryMetadataSaveJob : MediaLibraryScanJob, IReposito
|
||||
{
|
||||
try
|
||||
{
|
||||
parentsPayloadsExecuted++; // increment the number of parents that finished their execution and called this job
|
||||
// increment the number of parents that finished their execution and called this job (beware race conditions, jobs run in parallel)
|
||||
int parentsCompleted = Interlocked.Increment(ref parentsPayloadsExecuted);
|
||||
// only execute this job's payload when it has no parents, or when all the parents finished their execution
|
||||
if (Parents.Count == 0 || parentsPayloadsExecuted == Parents.Count)
|
||||
if (Parents.Count == 0 || parentsCompleted == Parents.Count)
|
||||
{
|
||||
// this needs to be wrapped in a task because even though this job is processed in a "fire and forget" async manner, it still does synchronous
|
||||
// file system processing that takes time, and would block the processing of scan jobs in the in-memory queue
|
||||
|
||||
+3
-2
@@ -45,9 +45,10 @@ internal sealed class GoodReadsMetadataScrapJob : MediaLibraryScanJob, IGoodRead
|
||||
{
|
||||
try
|
||||
{
|
||||
parentsPayloadsExecuted++; // increment the number of parents that finished their execution and called this job
|
||||
// increment the number of parents that finished their execution and called this job (beware race conditions, jobs run in parallel)
|
||||
int parentsCompleted = Interlocked.Increment(ref parentsPayloadsExecuted);
|
||||
// only execute this job's payload when it has no parents, or when all the parents finished their execution
|
||||
if (Parents.Count == 0 || parentsPayloadsExecuted == Parents.Count)
|
||||
if (Parents.Count == 0 || parentsCompleted == Parents.Count)
|
||||
{
|
||||
Status = LibraryScanJobStatus.Running;
|
||||
Console.WriteLine("started goodreads metadata");
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.Library
|
||||
using System.Threading.Channels;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Queue;
|
||||
namespace Lumina.Infrastructure.Core.MediaLibrary.Management.Scanning.Queue;
|
||||
|
||||
/// <summary>
|
||||
/// Provides an in-memory message queue for handling <see cref="IMediaLibraryScanJob"/> instances.
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Queue;
|
||||
namespace Lumina.Infrastructure.Core.MediaLibrary.Management.Scanning.Queue;
|
||||
|
||||
/// <summary>
|
||||
/// Background service for processing media library scan jobs from an in-memory message queue.
|
||||
|
||||
Reference in new issue
Block a user