refactor(architecture): harden module boundaries
Some checks failed
ci / release-gate (push) Has been cancelled
Some checks failed
ci / release-gate (push) Has been cancelled
This commit is contained in:
@@ -20,7 +20,7 @@ internal sealed partial class BackgroundJobService
|
||||
{
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
var leaseExpiresAt = now.Add(LeaseDuration);
|
||||
var claimedIds = await dbContext.Database.SqlQuery<Guid>($"""
|
||||
var claimedIds = await unitOfWork.Database.SqlQuery<Guid>($"""
|
||||
UPDATE background_jobs AS job
|
||||
SET status = 'processing',
|
||||
locked_by = {workerId},
|
||||
@@ -44,13 +44,13 @@ internal sealed partial class BackgroundJobService
|
||||
.ToArrayAsync(cancellationToken);
|
||||
|
||||
var processed = 0;
|
||||
dbContext.ChangeTracker.Clear();
|
||||
unitOfWork.ChangeTracker.Clear();
|
||||
foreach (var jobId in claimedIds)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var job = await dbContext.BackgroundJobs.SingleAsync(value => value.Id == jobId, cancellationToken);
|
||||
var job = await jobsOperationsPersistence.BackgroundJobs.SingleAsync(value => value.Id == jobId, cancellationToken);
|
||||
if (await ProcessJobAsync(job, workerId, true, cancellationToken)) processed++;
|
||||
dbContext.ChangeTracker.Clear();
|
||||
unitOfWork.ChangeTracker.Clear();
|
||||
}
|
||||
|
||||
return processed;
|
||||
@@ -64,7 +64,7 @@ internal sealed partial class BackgroundJobService
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var normalizedJobType = NormalizeJobType(jobType);
|
||||
var claimed = await dbContext.BackgroundJobs
|
||||
var claimed = await jobsOperationsPersistence.BackgroundJobs
|
||||
.Where(item => item.Id == jobId && item.TenantId == tenantId &&
|
||||
item.JobType == normalizedJobType && item.Status == BackgroundJobStatus.Pending &&
|
||||
item.RunAfter == null)
|
||||
@@ -75,8 +75,8 @@ internal sealed partial class BackgroundJobService
|
||||
.SetProperty(item => item.StartedAt, DateTimeOffset.UtcNow), cancellationToken);
|
||||
if (claimed == 0) return false;
|
||||
|
||||
dbContext.ChangeTracker.Clear();
|
||||
var job = await dbContext.BackgroundJobs.SingleOrDefaultAsync(
|
||||
unitOfWork.ChangeTracker.Clear();
|
||||
var job = await jobsOperationsPersistence.BackgroundJobs.SingleOrDefaultAsync(
|
||||
item => item.Id == jobId && item.TenantId == tenantId,
|
||||
cancellationToken);
|
||||
if (job is null)
|
||||
@@ -96,7 +96,7 @@ internal sealed partial class BackgroundJobService
|
||||
if ((!alreadyClaimed && job.Status != BackgroundJobStatus.Pending) ||
|
||||
(alreadyClaimed && (job.Status != BackgroundJobStatus.Processing || job.LockedBy != workerId)))
|
||||
return false;
|
||||
await dbContext.Entry(job).ReloadAsync(cancellationToken);
|
||||
await unitOfWork.Entry(job).ReloadAsync(cancellationToken);
|
||||
if (job.CancellationRequestedAt.HasValue)
|
||||
{
|
||||
job.CompletedAt = DateTimeOffset.UtcNow;
|
||||
@@ -133,7 +133,7 @@ internal sealed partial class BackgroundJobService
|
||||
job.LockedBy = workerId;
|
||||
job.LockExpiresAt = now.Add(LeaseDuration);
|
||||
job.StartedAt = now;
|
||||
await dbContext.SaveChangesAsync(cancellationToken);
|
||||
await unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
|
||||
try
|
||||
@@ -151,7 +151,7 @@ internal sealed partial class BackgroundJobService
|
||||
token);
|
||||
},
|
||||
cancellationToken);
|
||||
var cancellationRequested = await dbContext.BackgroundJobs.AsNoTracking()
|
||||
var cancellationRequested = await jobsOperationsPersistence.BackgroundJobs.AsNoTracking()
|
||||
.Where(item => item.Id == job.Id)
|
||||
.Select(item => item.CancellationRequestedAt != null)
|
||||
.SingleAsync(cancellationToken);
|
||||
@@ -213,7 +213,7 @@ internal sealed partial class BackgroundJobService
|
||||
string? lastError,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
await dbContext.BackgroundJobs
|
||||
await jobsOperationsPersistence.BackgroundJobs
|
||||
.Where(value => value.Id == job.Id && value.LockedBy == workerId)
|
||||
.ExecuteUpdateAsync(setters => setters
|
||||
.SetProperty(value => value.Status, status)
|
||||
|
||||
Reference in New Issue
Block a user