清理代码
Some checks failed
ci / release-gate (push) Has been cancelled

This commit is contained in:
2026-08-03 12:31:39 +08:00
parent caea0062b0
commit c497a3ca8d
537 changed files with 14171 additions and 12503 deletions

View File

@@ -1,20 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using System.Formats.Tar;
using System.IO.Compression;
using Tiku.Application.Assets;
using Tiku.Application.Content;
using Tiku.Application.Jobs;
using Tiku.Application.Security;
using Tiku.Application.Tenancy;
using Tiku.Domain.Commerce;
using Tiku.Domain.Common;
using Tiku.Domain.Content;
using Tiku.Domain.Operations;
using Tiku.Infrastructure.Persistence;
using Tiku.Infrastructure.Observability;
using System.Diagnostics;
namespace Tiku.Infrastructure.Jobs;
@@ -32,10 +19,7 @@ internal sealed partial class BackgroundJobService
item => item.TenantId == command.TenantId && item.JobType == normalizedJobType &&
item.IdempotencyKey == idempotencyKey,
cancellationToken);
if (existing is not null)
{
return ToItem(existing);
}
if (existing is not null) return ToItem(existing);
}
if (!command.IsSystemJob && !(await featureAccessService.EvaluateAsync(
@@ -43,9 +27,7 @@ internal sealed partial class BackgroundJobService
ResolveRequiredFeature(normalizedJobType, command.Payload),
FeatureAccessOperation.Write,
cancellationToken)).Allowed)
{
throw new InvalidOperationException("Tenant feature entitlement does not allow this background job.");
}
var quotaMetric = command.IsSystemJob ? null : ResolveQuotaMetric(normalizedJobType);
var quotaConsumed = false;
if (quotaMetric is not null)
@@ -57,11 +39,11 @@ internal sealed partial class BackgroundJobService
quotaConsumed = await featureAccessService.TryConsumeQuotaAsync(
command.TenantId, quotaMetric, 1, cancellationToken);
if (!quotaConsumed)
{
throw new FeatureAccessException("The background job quota has been exhausted.", "feature_quota_exhausted");
}
throw new FeatureAccessException("The background job quota has been exhausted.",
"feature_quota_exhausted");
}
}
var job = new BackgroundJob
{
TenantId = command.TenantId,
@@ -86,30 +68,30 @@ internal sealed partial class BackgroundJobService
if (existing is not null)
{
if (quotaConsumed && quotaMetric is not null)
{
await featureAccessService.ReleaseQuotaAsync(command.TenantId, quotaMetric, 1, CancellationToken.None);
}
await featureAccessService.ReleaseQuotaAsync(command.TenantId, quotaMetric, 1,
CancellationToken.None);
return ToItem(existing);
}
throw;
}
catch
{
if (quotaConsumed && quotaMetric is not null)
{
await featureAccessService.ReleaseQuotaAsync(command.TenantId, quotaMetric, 1, CancellationToken.None);
}
throw;
}
return ToItem(job);
}
private static string? ResolveQuotaMetric(string jobType) => jobType switch
private static string? ResolveQuotaMetric(string jobType)
{
"content_import" => SaasQuotaMetricCatalog.ImportCount,
"content_export" => SaasQuotaMetricCatalog.ExportCount,
_ => null
};
}
return jobType switch
{
"content_import" => SaasQuotaMetricCatalog.ImportCount,
"content_export" => SaasQuotaMetricCatalog.ExportCount,
_ => null
};
}
}