|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Quartz;
|
|
|
|
|
using Volo.Abp.BackgroundJobs.DemoApp.Shared.Jobs;
|
|
|
|
@ -9,34 +10,32 @@ namespace Volo.Abp.BackgroundJobs.DemoApp.Quartz;
|
|
|
|
|
|
|
|
|
|
class Program
|
|
|
|
|
{
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
async static Task Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
using (var application = AbpApplicationFactory.Create<DemoAppQuartzModule>(options =>
|
|
|
|
|
using (var application = await AbpApplicationFactory.CreateAsync<DemoAppQuartzModule>(options =>
|
|
|
|
|
{
|
|
|
|
|
options.UseAutofac();
|
|
|
|
|
}))
|
|
|
|
|
{
|
|
|
|
|
application.Initialize();
|
|
|
|
|
await application.InitializeAsync();
|
|
|
|
|
|
|
|
|
|
await CancelableBackgroundJobAsync(application.ServiceProvider);
|
|
|
|
|
|
|
|
|
|
CancelableBackgroundJob(application.ServiceProvider);
|
|
|
|
|
Console.WriteLine("Started: " + typeof(Program).Namespace);
|
|
|
|
|
Console.WriteLine("Press ENTER to stop the application..!");
|
|
|
|
|
Console.ReadLine();
|
|
|
|
|
|
|
|
|
|
application.Shutdown();
|
|
|
|
|
await application.ShutdownAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void CancelableBackgroundJob(IServiceProvider serviceProvider)
|
|
|
|
|
|
|
|
|
|
private async static Task CancelableBackgroundJobAsync(IServiceProvider serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
AsyncHelper.RunSync(async () =>
|
|
|
|
|
{
|
|
|
|
|
var backgroundJobManager = serviceProvider.GetRequiredService<IBackgroundJobManager>();
|
|
|
|
|
var jobId = await backgroundJobManager.EnqueueAsync(new LongRunningJobArgs { Value = "test-1" });
|
|
|
|
|
await backgroundJobManager.EnqueueAsync(new LongRunningJobArgs { Value = "test-2" });
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
var scheduler = serviceProvider.GetRequiredService<IScheduler>();
|
|
|
|
|
await scheduler.Interrupt(new JobKey(jobId.Split('.')[1],jobId.Split('.')[0]));
|
|
|
|
|
});
|
|
|
|
|
var backgroundJobManager = serviceProvider.GetRequiredService<IBackgroundJobManager>();
|
|
|
|
|
var jobId = await backgroundJobManager.EnqueueAsync(new LongRunningJobArgs {Value = "test-1"});
|
|
|
|
|
await backgroundJobManager.EnqueueAsync(new LongRunningJobArgs { Value = "test-2" });
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
var scheduler = serviceProvider.GetRequiredService<IScheduler>();
|
|
|
|
|
await scheduler.Interrupt(new JobKey(jobId.Split('.')[1],jobId.Split('.')[0]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|