feat(新增): 尝试加入quartz
This commit is contained in:
parent
63c8032169
commit
e48c71c1e1
|
@ -9,6 +9,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Fleck" Version="1.2.0"/>
|
<PackageReference Include="Fleck" Version="1.2.0"/>
|
||||||
<PackageReference Include="Lazy.Captcha.Core" Version="2.0.8"/>
|
<PackageReference Include="Lazy.Captcha.Core" Version="2.0.8"/>
|
||||||
|
<PackageReference Include="Quartz.Extensions.Hosting" Version="3.13.0"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
using Quartz;
|
||||||
|
|
||||||
|
namespace Bunny.Service.Job;
|
||||||
|
|
||||||
|
public class HelloJob : IJob
|
||||||
|
{
|
||||||
|
public Task Execute(IJobExecutionContext context)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Hello World 的自动执行");
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
using Bunny.Service.Job;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using Quartz;
|
||||||
|
|
||||||
|
namespace Bunny.Test.Until.JobTest;
|
||||||
|
|
||||||
|
public class JobTest1
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
[Obsolete("Obsolete")]
|
||||||
|
public async Task TestJob()
|
||||||
|
{
|
||||||
|
var scheduler = await Host.CreateDefaultBuilder()
|
||||||
|
.ConfigureServices((_, services) =>
|
||||||
|
{
|
||||||
|
services.AddQuartzHostedService(opt => { opt.WaitForJobsToComplete = true; });
|
||||||
|
services.AddQuartz(q => q.UseMicrosoftDependencyInjectionJobFactory());
|
||||||
|
})
|
||||||
|
.Build()
|
||||||
|
.Services.GetRequiredService<ISchedulerFactory>()
|
||||||
|
.GetScheduler();
|
||||||
|
var jobDetail = JobBuilder.Create<HelloJob>()
|
||||||
|
.WithIdentity("HelloJob", "分组名称")
|
||||||
|
.Build();
|
||||||
|
var trigger = TriggerBuilder.Create()
|
||||||
|
.WithIdentity("HelloJob", "触发器分组")
|
||||||
|
.StartNow()
|
||||||
|
.WithSimpleSchedule(x => x.WithIntervalInSeconds(5).WithRepeatCount(5))
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
await scheduler.ScheduleJob(jobDetail, trigger);
|
||||||
|
await scheduler.Start();
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,15 +3,48 @@
|
||||||
<Assembly Path="D:\software\Microsoft\Visual Studio\packages\stackexchange.redis\2.7.33\lib\net6.0\StackExchange.Redis.dll" />
|
<Assembly Path="D:\software\Microsoft\Visual Studio\packages\stackexchange.redis\2.7.33\lib\net6.0\StackExchange.Redis.dll" />
|
||||||
<Assembly Path="D:\software\Microsoft\Visual Studio\packages\minio\6.0.2\lib\net7.0\Minio.dll" />
|
<Assembly Path="D:\software\Microsoft\Visual Studio\packages\minio\6.0.2\lib\net7.0\Minio.dll" />
|
||||||
</AssemblyExplorer></s:String>
|
</AssemblyExplorer></s:String>
|
||||||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=eb9da086_002D824a_002D4ac4_002Db755_002D94438e510122/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="Test1" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=22382ad8_002Dcbf4_002D4254_002Da582_002D16e6116533ce/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="TestJob #3" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
||||||
<TestAncestor>
|
<TestAncestor>
|
||||||
<TestId>NUnit3x::945BE294-8057-40EE-9A98-5598D1A728B9::net8.0::Bunny.Test.Until.NetUtilTest.Encryption32Lower</TestId>
|
<TestId>NUnit3x::945BE294-8057-40EE-9A98-5598D1A728B9::net8.0::Bunny.Test.Until.JobTest.JobTest1.TestJob</TestId>
|
||||||
<TestId>NUnit3x::945BE294-8057-40EE-9A98-5598D1A728B9::net8.0::Bunny.Test.Until.NetUtilTest.GetProperties</TestId>
|
|
||||||
<TestId>NUnit3x::945BE294-8057-40EE-9A98-5598D1A728B9::net8.0::Bunny.Test.Until.Redis.RedisConnect.RedisConnectTest</TestId>
|
|
||||||
<TestId>xUnit::945BE294-8057-40EE-9A98-5598D1A728B9::net8.0::Bunny.Test.Until.Redis.RedisConnect.RedisConnectTest</TestId>
|
|
||||||
<TestId>NUnit3x::945BE294-8057-40EE-9A98-5598D1A728B9::net8.0::Bunny.Test.Until.EfCoreTest.EfCoreTest.TestDbConnection</TestId>
|
|
||||||
</TestAncestor>
|
</TestAncestor>
|
||||||
</SessionState></s:String>
|
</SessionState></s:String>
|
||||||
|
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=3350941e_002Db049_002D4958_002D9739_002D2bfbfcc03e72/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="TestJob #4" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
||||||
|
<TestAncestor>
|
||||||
|
<TestId>NUnit3x::945BE294-8057-40EE-9A98-5598D1A728B9::net8.0::Bunny.Test.Until.JobTest.JobTest1.TestJob</TestId>
|
||||||
|
</TestAncestor>
|
||||||
|
</SessionState></s:String>
|
||||||
|
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=72bdef07_002Da453_002D48bb_002Db9e3_002D1539d922644a/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="TestJob" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
||||||
|
<TestAncestor>
|
||||||
|
<TestId>NUnit3x::945BE294-8057-40EE-9A98-5598D1A728B9::net8.0::Bunny.Test.Until.JobTest.JobTest1.TestJob</TestId>
|
||||||
|
</TestAncestor>
|
||||||
|
</SessionState></s:String>
|
||||||
|
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=83126680_002Dc767_002D40a2_002Dadfd_002Daa4542ab8b4b/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="TestJob #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
||||||
|
<TestAncestor>
|
||||||
|
<TestId>NUnit3x::945BE294-8057-40EE-9A98-5598D1A728B9::net8.0::Bunny.Test.Until.JobTest.JobTest1.TestJob</TestId>
|
||||||
|
</TestAncestor>
|
||||||
|
</SessionState></s:String>
|
||||||
|
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=eb9da086_002D824a_002D4ac4_002Db755_002D94438e510122/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="Test1" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
||||||
|
<Or>
|
||||||
|
<And>
|
||||||
|
<TestAncestor>
|
||||||
|
<TestId>NUnit3x::945BE294-8057-40EE-9A98-5598D1A728B9::net8.0::Bunny.Test.Until.NetUtilTest.Encryption32Lower</TestId>
|
||||||
|
<TestId>NUnit3x::945BE294-8057-40EE-9A98-5598D1A728B9::net8.0::Bunny.Test.Until.NetUtilTest.GetProperties</TestId>
|
||||||
|
<TestId>NUnit3x::945BE294-8057-40EE-9A98-5598D1A728B9::net8.0::Bunny.Test.Until.Redis.RedisConnect.RedisConnectTest</TestId>
|
||||||
|
<TestId>xUnit::945BE294-8057-40EE-9A98-5598D1A728B9::net8.0::Bunny.Test.Until.Redis.RedisConnect.RedisConnectTest</TestId>
|
||||||
|
<TestId>NUnit3x::945BE294-8057-40EE-9A98-5598D1A728B9::net8.0::Bunny.Test.Until.EfCoreTest.EfCoreTest.TestDbConnection</TestId>
|
||||||
|
<TestId>NUnit3x::945BE294-8057-40EE-9A98-5598D1A728B9::net8.0::Bunny.Test.Until.JobTest.JobTest1.TestJob</TestId>
|
||||||
|
</TestAncestor>
|
||||||
|
<Not>
|
||||||
|
<TestAncestor>
|
||||||
|
<TestId>NUnit3x::945BE294-8057-40EE-9A98-5598D1A728B9::net8.0::Bunny.Test.Until.JobTest.JobTest1.TestJob</TestId>
|
||||||
|
</TestAncestor>
|
||||||
|
</Not>
|
||||||
|
</And>
|
||||||
|
<TestAncestor>
|
||||||
|
<TestId>NUnit3x::945BE294-8057-40EE-9A98-5598D1A728B9::net8.0::Bunny.Test.Until.JobTest.JobTest1.TestJob</TestId>
|
||||||
|
</TestAncestor>
|
||||||
|
</Or>
|
||||||
|
</SessionState></s:String>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,6 @@ public class Program
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
// app.UseWebSockets();
|
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
"Audience": "Audience"
|
"Audience": "Audience"
|
||||||
},
|
},
|
||||||
"Redis": {
|
"Redis": {
|
||||||
"Host": "192.168.3.98",
|
"Host": "47.120.65.66",
|
||||||
"Port": "6379",
|
"Port": "6379",
|
||||||
"Password": "123456",
|
"Password": "02120212",
|
||||||
"DefaultDB": 6,
|
"DefaultDB": 6,
|
||||||
"AsyncTimeout": 300
|
"AsyncTimeout": 300
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue