网站首页 网站源码
website
站点相关全部源代码,隐藏了一些关于服务器的信息
namespace Dpz.Core.Service.RepositoryServiceImpl;

public class WaitExecutionService(IRepository<WaitExecution> repository, IMapper mapper)
    : IWaitExecutionService
{
    public async Task<IList<VmWaitExecution>> GetNotExecuteTaskAsync()
    {
        var list = await repository
            .SearchFor(x => x.Status != ExecuteStatus.ExecuteComplete)
            .OrderBy(x => x.Id)
            .Take(1000)
            .ToListAsync();
        return mapper.Map<List<VmWaitExecution>>(list);
    }

    public async Task UpdateStatusAsync(string id, ExecuteStatus status)
    {
        if (ObjectId.TryParse(id, out var oid))
        {
            var update = Builders<WaitExecution>
                .Update.Set(x => x.Status, status)
                .Set(x => x.LastUpdateTime, DateTime.Now);
            await repository.UpdateAsync(x => x.Id == oid, update);
        }
    }

    public async Task ClearExpiredAsync()
    {
        var ids = await repository
            .SearchFor(x => x.Status == ExecuteStatus.ExecuteComplete)
            .OrderByDescending(x => x.Id)
            .ThenByDescending(x => x.LastUpdateTime)
            .Take(1000)
            .Select(x => x.Id)
            .ToListAsync();

        var filter = Builders<WaitExecution>.Filter.In(x => x.Id, ids);
        await repository.DeleteAsync(filter);
    }

    public async Task AddToTaskAsync(
        IReadOnlyCollection<ObjectId>? images,
        IReadOnlyCollection<string>? imageUrls
    )
    {
        //images ??= new List<ObjectId>();
        imageUrls ??= new List<string>();

        // var pictureKeys = images.Select(x => x.ToString()).ToList();
        // pictureKeys.AddRange(imageUrls);
        // var filter = Builders<Picture>.Filter.In(x => x.Info.Delete, pictureKeys);
        // await _pictureRepository.DeleteAsync(filter);

        var imageTasks = imageUrls
            .Select(x => new WaitExecution
            {
                Category = ExecuteCategory.Delete,
                Relation = x,
                Scheme = ExecuteScheme.DeleteUpyun,
                Status = ExecuteStatus.NotExecute,
                CreateTime = DateTime.Now,
                LastUpdateTime = null
            })
            .ToList();

        // var dbImages = images.Select(x => new WaitExecution
        // {
        //     Category = ExecuteCategory.Delete,
        //     Relation = x.ToString(),
        //     Scheme = ExecuteScheme.DeleteDbFile,
        //     Status = ExecuteStatus.NotExecute,
        //     CreateTime = DateTime.Now,
        //     LastUpdateTime = null
        // }).ToArray();

        //imageTasks.AddRange(dbImages);
        if (imageTasks.Count > 0)
            await AddExecuteTaskAsync(imageTasks.ToArray());
    }

    public async Task AddExecuteTaskAsync(params WaitExecution[] task)
    {
        await repository.InsertAsync(task);
    }
}
loading