feat Hnagfire初步搭建
This commit is contained in:
@@ -15,5 +15,7 @@ public class Startup : DefaultStartup
|
||||
public Startup(IConfiguration configuration) : base(configuration)
|
||||
{
|
||||
IdentityModelEventSource.ShowPII = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
@@ -17,6 +17,10 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.6" />
|
||||
<PackageReference Include="Hangfire.Dashboard.BasicAuthorization" Version="1.0.2" />
|
||||
<PackageReference Include="Hangfire.MySql.Core_MySql.Data" Version="2.1.10" />
|
||||
<PackageReference Include="Hangfire.MySqlStorage" Version="2.0.2" />
|
||||
<PackageReference Include="Kurisu.AspNetCore" Version="0.4.7" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
12
Src/Dlhis.ScheduledTask/MyBackgroundJobService.cs
Normal file
12
Src/Dlhis.ScheduledTask/MyBackgroundJobService.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Hangfire;
|
||||
|
||||
namespace Dlhis.ScheduledTask
|
||||
{
|
||||
public class MyBackgroundJobService
|
||||
{
|
||||
public void EnqueueMyJob()
|
||||
{
|
||||
BackgroundJob.Enqueue(() => Console.WriteLine("This is a background job."));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using Kurisu.AspNetCore.Startup;
|
||||
using Kurisu.Startup;
|
||||
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
@@ -15,4 +16,5 @@ public class Startup : DefaultStartup
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
34
Src/Dlhis.ScheduledTask/SqlSugarPack1.cs
Normal file
34
Src/Dlhis.ScheduledTask/SqlSugarPack1.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Hangfire;
|
||||
using Hangfire.MySql;
|
||||
using Kurisu.AspNetCore.Startup;
|
||||
|
||||
namespace Dlhis.ScheduledTask
|
||||
{
|
||||
public class SqlSugarPack1 : BaseAppPack
|
||||
{
|
||||
public override bool IsBeforeUseRouting { get; }
|
||||
|
||||
public override void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddHangfire(configuration => configuration
|
||||
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
|
||||
.UseSimpleAssemblyNameTypeSerializer()
|
||||
.UseRecommendedSerializerSettings()
|
||||
.UseStorage(
|
||||
new MySqlStorage(
|
||||
Configuration.GetConnectionString("HangfireConnection"),
|
||||
new MySqlStorageOptions
|
||||
{
|
||||
TablesPrefix = "Hangfire" // Adjust other options as needed
|
||||
}
|
||||
)
|
||||
));
|
||||
services.AddHangfireServer();
|
||||
}
|
||||
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
app.UseHangfireDashboard(); //使用hangfire面板
|
||||
app.UseHangfireServer(); //启动hangfire服务
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"HangfireConnection": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=Hangfire;charset=utf8mb4;Allow User Variables=true;"
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
|
||||
Reference in New Issue
Block a user