修改BackgroundWorker BUG

This commit is contained in:
cli 2025-03-14 13:45:29 +08:00
parent 0b0eaa6ad0
commit c174738095
7 changed files with 59 additions and 13 deletions

View File

@ -11,6 +11,8 @@ using JiShe.CollectBus.FreeSql;
using System; using System;
using Volo.Abp.AspNetCore.Mvc.AntiForgery; using Volo.Abp.AspNetCore.Mvc.AntiForgery;
using JiShe.CollectBus.FreeRedisProvider; using JiShe.CollectBus.FreeRedisProvider;
using JiShe.CollectBus.Workers;
using Volo.Abp.BackgroundWorkers.Hangfire;
namespace JiShe.CollectBus; namespace JiShe.CollectBus;
@ -19,7 +21,7 @@ namespace JiShe.CollectBus;
typeof(CollectBusApplicationContractsModule), typeof(CollectBusApplicationContractsModule),
typeof(AbpDddApplicationModule), typeof(AbpDddApplicationModule),
typeof(AbpAutoMapperModule), typeof(AbpAutoMapperModule),
typeof(AbpBackgroundWorkersModule), typeof(AbpBackgroundWorkersHangfireModule),
typeof(FreeRedisProviderModule), typeof(FreeRedisProviderModule),
typeof(CollectBusFreeSqlModule) typeof(CollectBusFreeSqlModule)
)] )]
@ -40,7 +42,7 @@ public class CollectBusApplicationModule : AbpModule
}); });
} }
public override async Task OnApplicationInitializationAsync( public override void OnApplicationInitialization(
ApplicationInitializationContext context) ApplicationInitializationContext context)
{ {
var assembly = Assembly.GetExecutingAssembly(); var assembly = Assembly.GetExecutingAssembly();
@ -48,7 +50,7 @@ public class CollectBusApplicationModule : AbpModule
foreach (var type in types) foreach (var type in types)
{ {
await context.AddBackgroundWorkerAsync(type); context.AddBackgroundWorkerAsync(type);
} }
} }

View File

@ -1,8 +1,10 @@
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Hangfire;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Volo.Abp.BackgroundWorkers.Hangfire; using Volo.Abp.BackgroundWorkers.Hangfire;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Uow;
namespace JiShe.CollectBus.Workers namespace JiShe.CollectBus.Workers
{ {
@ -17,13 +19,18 @@ namespace JiShe.CollectBus.Workers
public EpiCollectWorker(ILogger<EpiCollectWorker> logger) public EpiCollectWorker(ILogger<EpiCollectWorker> logger)
{ {
_logger = logger; _logger = logger;
RecurringJobId = nameof(EpiCollectWorker);
CronExpression = Cron.Daily();
} }
public override Task DoWorkAsync(CancellationToken cancellationToken = new CancellationToken()) public override Task DoWorkAsync(CancellationToken cancellationToken = new CancellationToken())
{ {
_logger.LogError("Executed MyLogWorker..!"); using (var uow = LazyServiceProvider.LazyGetRequiredService<IUnitOfWorkManager>().Begin())
{
Logger.LogInformation("Executed MyLogWorker..!");
return Task.CompletedTask; return Task.CompletedTask;
} }
} }
} }
}

View File

@ -8,8 +8,11 @@
<ItemGroup> <ItemGroup>
<Compile Remove="Abstractions\**" /> <Compile Remove="Abstractions\**" />
<Compile Remove="Interfaces\**" />
<EmbeddedResource Remove="Abstractions\**" /> <EmbeddedResource Remove="Abstractions\**" />
<EmbeddedResource Remove="Interfaces\**" />
<None Remove="Abstractions\**" /> <None Remove="Abstractions\**" />
<None Remove="Interfaces\**" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -24,8 +27,4 @@
<PackageReference Include="Volo.Abp.Ddd.Domain" Version="8.3.3" /> <PackageReference Include="Volo.Abp.Ddd.Domain" Version="8.3.3" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Interfaces\" />
</ItemGroup>
</Project> </Project>

View File

@ -20,7 +20,10 @@
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Localization\CollectBus\*.json" /> <EmbeddedResource Include="Localization\CollectBus\*.json" />
<Compile Remove="Caches\**" />
<Content Remove="Localization\CollectBus\*.json" /> <Content Remove="Localization\CollectBus\*.json" />
<EmbeddedResource Remove="Caches\**" />
<None Remove="Caches\**" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -28,8 +31,4 @@
<None Remove="JiShe.CollectBus.Domain.Shared.abppkg" /> <None Remove="JiShe.CollectBus.Domain.Shared.abppkg" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Caches\" />
</ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,34 @@
using System;
using Microsoft.Extensions.Logging;
namespace JiShe.CollectBus.Loggers
{
public static class LoggerExtensions
{
public static void LogInfoToMongo(
this ILogger logger,
EventId eventId,
Exception? exception,
string? message,
params object?[] args)
{
}
public static void LogInfoToMongo(this ILogger logger)
{
}
private static void Log(
this ILogger logger,
LogLevel logLevel,
EventId eventId,
string? message,
params object?[] args)
{
}
}
}

View File

@ -26,4 +26,8 @@
<PackageReference Include="Volo.Abp.AuditLogging.Domain" Version="8.3.3" /> <PackageReference Include="Volo.Abp.AuditLogging.Domain" Version="8.3.3" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Loggers\" />
</ItemGroup>
</Project> </Project>

View File

@ -39,6 +39,7 @@ namespace JiShe.CollectBus.Host
public void Configure(IApplicationBuilder app, IHostApplicationLifetime lifetime) public void Configure(IApplicationBuilder app, IHostApplicationLifetime lifetime)
{ {
app.InitializeApplication(); app.InitializeApplication();
//await app.InitializeApplicationAsync();
} }
} }
} }