23 lines
1013 B
C#
23 lines
1013 B
C#
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Store.Modules.CloudProduct.Services;
|
|
|
|
/// <summary>
|
|
/// 违规商品搜索索引清理任务,由 CloudProductPlugin 注册为每分钟执行一次。
|
|
/// 每批处理最多 1000 个尚未完成索引删除的违规商品,循环处理至无待处理记录。
|
|
/// </summary>
|
|
public class GoodsViolationIndexJob(IServiceScopeFactory scopeFactory)
|
|
{
|
|
/// <summary>
|
|
/// 删除待处理商品的 OpenSearch 索引,成功后将违规记录的 IsIndexDeleted 标记为 true。
|
|
/// 失败时异常交由 Hangfire 处理,尚未标记完成的记录留待后续执行继续处理。
|
|
/// </summary>
|
|
public async Task ProcessPendingAsync()
|
|
{
|
|
// 为本次任务创建独立作用域,执行结束后释放业务服务及其作用域依赖。
|
|
using var scope = scopeFactory.CreateScope();
|
|
await scope.ServiceProvider.GetRequiredService<GoodsViolationService>()
|
|
.DeleteViolationIndexesAsync();
|
|
}
|
|
}
|