♻️ Extract the Storage service to DysonNetwork.Drive microservice
This commit is contained in:
27
DysonNetwork.Drive/Handlers/ActionLogFlushHandler.cs
Normal file
27
DysonNetwork.Drive/Handlers/ActionLogFlushHandler.cs
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
using EFCore.BulkExtensions;
|
||||
using Quartz;
|
||||
using DysonNetwork.Sphere;
|
||||
using DysonNetwork.Common.Models;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DysonNetwork.Drive.Handlers;
|
||||
|
||||
public class ActionLogFlushHandler(IServiceProvider serviceProvider) : IFlushHandler<ActionLog>
|
||||
{
|
||||
public async Task FlushAsync(IReadOnlyList<ActionLog> items)
|
||||
{
|
||||
using var scope = serviceProvider.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<AppDatabase>();
|
||||
|
||||
await db.BulkInsertAsync(items, config => config.ConflictOption = ConflictOption.Ignore);
|
||||
}
|
||||
}
|
||||
|
||||
public class ActionLogFlushJob(FlushBufferService fbs, ActionLogFlushHandler hdl) : IJob
|
||||
{
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
await fbs.FlushAsync(hdl);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user