mirror of https://github.com/abpframework/abp.git
49 changed files with 1356 additions and 84 deletions
@ -0,0 +1,38 @@ |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Hangfire; |
|||
using Volo.Abp.BackgroundWorkers.Hangfire; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp.HangFire; |
|||
|
|||
public class MyLogWorker : HangfireBackgroundWorkerBase |
|||
{ |
|||
public MyLogWorker() |
|||
{ |
|||
RecurringJobId = nameof(MyLogWorker); |
|||
CronExpression = Cron.Minutely(); |
|||
} |
|||
|
|||
public override Task DoWorkAsync(CancellationToken cancellationToken = default) |
|||
{ |
|||
Console.WriteLine("Executed MyLogWorker..!"); |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
|
|||
public class MyLogWorker2 : HangfireBackgroundWorkerBase |
|||
{ |
|||
public MyLogWorker2() |
|||
{ |
|||
RecurringJobId = nameof(MyLogWorker2); |
|||
CronExpression = Cron.Minutely(); |
|||
Queue = "my_queue"; |
|||
} |
|||
|
|||
public override Task DoWorkAsync(CancellationToken cancellationToken = default) |
|||
{ |
|||
Console.WriteLine("Executed MyLogWorker2..!"); |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
@ -1,5 +1,5 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;Trusted_Connection=True;TrustServerCertificate=True" |
|||
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;User Id=sa;Password=1q2w3E***;TrustServerCertificate=True" |
|||
} |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
using System.Threading.Tasks; |
|||
using Hangfire; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Autofac; |
|||
using Volo.Abp.BackgroundJobs.DemoApp.Shared; |
|||
using Volo.Abp.BackgroundJobs.Hangfire; |
|||
using Volo.Abp.BackgroundWorkers; |
|||
using Volo.Abp.BackgroundWorkers.Hangfire; |
|||
using Volo.Abp.Hangfire; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp.HangFire2; |
|||
|
|||
[DependsOn( |
|||
typeof(DemoAppSharedModule), |
|||
typeof(AbpAutofacModule), |
|||
typeof(AbpBackgroundJobsHangfireModule), |
|||
typeof(AbpBackgroundWorkersHangfireModule) |
|||
)] |
|||
public class DemoAppHangfireModule : AbpModule |
|||
{ |
|||
public override void PreConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
var configuration = context.Services.GetConfiguration(); |
|||
|
|||
PreConfigure<IGlobalConfiguration>(hangfireConfiguration => |
|||
{ |
|||
hangfireConfiguration.UseSqlServerStorage(configuration.GetConnectionString("Default")); |
|||
}); |
|||
} |
|||
|
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
Configure<AbpHangfireOptions>(options => |
|||
{ |
|||
options.DefaultQueuePrefix = context.Services.GetApplicationName()!; |
|||
options.ServerOptions ??= new BackgroundJobServerOptions(); |
|||
options.ServerOptions.Queues = new[] { "default", "my_queue" }; |
|||
}); |
|||
|
|||
var configuration = context.Services.GetConfiguration(); |
|||
context.Services.AddHangfire(config => |
|||
{ |
|||
config.UseSqlServerStorage(configuration.GetConnectionString("Default")); |
|||
}); |
|||
} |
|||
|
|||
public async override Task OnApplicationInitializationAsync(ApplicationInitializationContext context) |
|||
{ |
|||
await context.AddBackgroundWorkerAsync<MyLogWorker>(); |
|||
await context.AddBackgroundWorkerAsync<MyLogWorker2>(); |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Hangfire; |
|||
using Volo.Abp.BackgroundWorkers.Hangfire; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp.HangFire2; |
|||
|
|||
public class MyLogWorker : HangfireBackgroundWorkerBase |
|||
{ |
|||
public MyLogWorker() |
|||
{ |
|||
RecurringJobId = nameof(MyLogWorker); |
|||
CronExpression = Cron.Minutely(); |
|||
} |
|||
|
|||
public override Task DoWorkAsync(CancellationToken cancellationToken = default) |
|||
{ |
|||
Console.WriteLine("Executed MyLogWorker..!"); |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
|
|||
public class MyLogWorker2 : HangfireBackgroundWorkerBase |
|||
{ |
|||
public MyLogWorker2() |
|||
{ |
|||
RecurringJobId = nameof(MyLogWorker2); |
|||
CronExpression = Cron.Minutely(); |
|||
Queue = "my_queue"; |
|||
} |
|||
|
|||
public override Task DoWorkAsync(CancellationToken cancellationToken = default) |
|||
{ |
|||
Console.WriteLine("Executed MyLogWorker2..!"); |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Hangfire; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.BackgroundJobs.DemoApp.Shared.Jobs; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp.HangFire2; |
|||
|
|||
class Program |
|||
{ |
|||
async static Task Main(string[] args) |
|||
{ |
|||
using (var application = await AbpApplicationFactory.CreateAsync<DemoAppHangfireModule>(options => |
|||
{ |
|||
options.UseAutofac(); |
|||
})) |
|||
{ |
|||
await application.InitializeAsync(); |
|||
|
|||
await CancelableBackgroundJobAsync(application.ServiceProvider); |
|||
|
|||
Console.WriteLine("Started: " + typeof(Program).Namespace); |
|||
Console.WriteLine("Press ENTER to stop the application..!"); |
|||
Console.ReadLine(); |
|||
|
|||
await application.ShutdownAsync(); |
|||
} |
|||
} |
|||
|
|||
private async static Task CancelableBackgroundJobAsync(IServiceProvider serviceProvider) |
|||
{ |
|||
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); |
|||
BackgroundJob.Delete(jobId); |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
{} |
|||
@ -0,0 +1,73 @@ |
|||
{ |
|||
"name": "Volo.Abp.BackgroundJobs.DemoApp.HangFire", |
|||
"hash": "a4ac122e27b8e7b2048e2c8803e8f6f0", |
|||
"contents": [ |
|||
{ |
|||
"namespace": "Volo.Abp.BackgroundJobs.DemoApp.HangFire", |
|||
"dependsOnModules": [ |
|||
{ |
|||
"declaringAssemblyName": "Volo.Abp.BackgroundJobs.DemoApp.Shared", |
|||
"namespace": "Volo.Abp.BackgroundJobs.DemoApp.Shared", |
|||
"name": "DemoAppSharedModule" |
|||
}, |
|||
{ |
|||
"declaringAssemblyName": "Volo.Abp.Autofac", |
|||
"namespace": "Volo.Abp.Autofac", |
|||
"name": "AbpAutofacModule" |
|||
}, |
|||
{ |
|||
"declaringAssemblyName": "Volo.Abp.BackgroundJobs.HangFire", |
|||
"namespace": "Volo.Abp.BackgroundJobs.Hangfire", |
|||
"name": "AbpBackgroundJobsHangfireModule" |
|||
} |
|||
], |
|||
"implementingInterfaces": [ |
|||
{ |
|||
"name": "IAbpModule", |
|||
"namespace": "Volo.Abp.Modularity", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.Modularity.IAbpModule" |
|||
}, |
|||
{ |
|||
"name": "IOnPreApplicationInitialization", |
|||
"namespace": "Volo.Abp.Modularity", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.Modularity.IOnPreApplicationInitialization" |
|||
}, |
|||
{ |
|||
"name": "IOnApplicationInitialization", |
|||
"namespace": "Volo.Abp", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.IOnApplicationInitialization" |
|||
}, |
|||
{ |
|||
"name": "IOnPostApplicationInitialization", |
|||
"namespace": "Volo.Abp.Modularity", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.Modularity.IOnPostApplicationInitialization" |
|||
}, |
|||
{ |
|||
"name": "IOnApplicationShutdown", |
|||
"namespace": "Volo.Abp", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.IOnApplicationShutdown" |
|||
}, |
|||
{ |
|||
"name": "IPreConfigureServices", |
|||
"namespace": "Volo.Abp.Modularity", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.Modularity.IPreConfigureServices" |
|||
}, |
|||
{ |
|||
"name": "IPostConfigureServices", |
|||
"namespace": "Volo.Abp.Modularity", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.Modularity.IPostConfigureServices" |
|||
} |
|||
], |
|||
"contentType": "abpModule", |
|||
"name": "DemoAppHangfireModule", |
|||
"summary": null |
|||
} |
|||
] |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<OutputType>Exe</OutputType> |
|||
<TargetFramework>net9.0</TargetFramework> |
|||
<RootNamespace>Volo.Abp.BackgroundJobs.DemoApp.HangFire2</RootNamespace> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Hangfire.SqlServer" /> |
|||
<PackageReference Include="Microsoft.Data.SqlClient" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.BackgroundJobs.HangFire\Volo.Abp.BackgroundJobs.HangFire.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.BackgroundWorkers.Hangfire\Volo.Abp.BackgroundWorkers.Hangfire.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.BackgroundJobs.DemoApp.Shared\Volo.Abp.BackgroundJobs.DemoApp.Shared.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<None Update="appsettings.json"> |
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|||
</None> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,5 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;User Id=sa;Password=1q2w3E***;TrustServerCertificate=True" |
|||
} |
|||
} |
|||
@ -1,16 +1,40 @@ |
|||
using Volo.Abp.Autofac; |
|||
using System.Collections.Specialized; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Autofac; |
|||
using Volo.Abp.BackgroundJobs.DemoApp.Shared; |
|||
using Volo.Abp.BackgroundJobs.Quartz; |
|||
using Volo.Abp.BackgroundWorkers.Quartz; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.Quartz; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp.Quartz; |
|||
|
|||
[DependsOn( |
|||
typeof(DemoAppSharedModule), |
|||
typeof(AbpAutofacModule), |
|||
typeof(AbpBackgroundJobsQuartzModule) |
|||
typeof(AbpBackgroundJobsQuartzModule), |
|||
typeof(AbpBackgroundWorkersQuartzModule) |
|||
)] |
|||
public class DemoAppQuartzModule : AbpModule |
|||
{ |
|||
|
|||
public override void PreConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
//https://github.com/quartznet/quartznet/blob/main/database/tables/tables_sqlServer.sql
|
|||
var configuration = context.Services.GetConfiguration(); |
|||
PreConfigure<AbpQuartzOptions>(options => |
|||
{ |
|||
options.Properties = new NameValueCollection |
|||
{ |
|||
["quartz.scheduler.instanceName"] = context.Services.GetApplicationName(), |
|||
["quartz.jobStore.dataSource"] = "BackgroundJobsDemoApp", |
|||
["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz", |
|||
["quartz.jobStore.tablePrefix"] = "QRTZ_", |
|||
["quartz.serializer.type"] = "json", |
|||
["quartz.dataSource.BackgroundJobsDemoApp.connectionString"] = configuration.GetConnectionString("Default"), |
|||
["quartz.dataSource.BackgroundJobsDemoApp.provider"] = "SqlServer", |
|||
["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz", |
|||
}; |
|||
}); |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Quartz; |
|||
using Volo.Abp.BackgroundWorkers.Quartz; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp.Quartz; |
|||
|
|||
public class MyLogWorker : QuartzBackgroundWorkerBase |
|||
{ |
|||
public MyLogWorker() |
|||
{ |
|||
JobDetail = JobBuilder.Create<MyLogWorker>().WithIdentity(nameof(MyLogWorker)).Build(); |
|||
Trigger = TriggerBuilder.Create().WithIdentity(nameof(MyLogWorker)).StartAt(DateTimeOffset.Now.AddSeconds(10)).Build(); |
|||
} |
|||
|
|||
public override Task Execute(IJobExecutionContext context) |
|||
{ |
|||
Console.WriteLine("Executed MyLogWorker..!"); |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
|
|||
public class MyLogWorker2 : QuartzBackgroundWorkerBase |
|||
{ |
|||
public MyLogWorker2() |
|||
{ |
|||
JobDetail = JobBuilder.Create<MyLogWorker2>().WithIdentity(nameof(MyLogWorker2)).Build(); |
|||
Trigger = TriggerBuilder.Create().WithIdentity(nameof(MyLogWorker2)).StartAt(DateTimeOffset.Now.AddSeconds(10)).Build(); |
|||
} |
|||
|
|||
public override Task Execute(IJobExecutionContext context) |
|||
{ |
|||
Console.WriteLine("Executed MyLogWorker2..!"); |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
@ -0,0 +1,5 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;User Id=sa;Password=1q2w3E***;TrustServerCertificate=True" |
|||
} |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
using System.Collections.Specialized; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Autofac; |
|||
using Volo.Abp.BackgroundJobs.DemoApp.Shared; |
|||
using Volo.Abp.BackgroundJobs.Quartz; |
|||
using Volo.Abp.BackgroundWorkers.Quartz; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.Quartz; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp.Quartz2; |
|||
|
|||
[DependsOn( |
|||
typeof(DemoAppSharedModule), |
|||
typeof(AbpAutofacModule), |
|||
typeof(AbpBackgroundJobsQuartzModule), |
|||
typeof(AbpBackgroundWorkersQuartzModule) |
|||
)] |
|||
public class DemoAppQuartzModule : AbpModule |
|||
{ |
|||
public override void PreConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
//https://github.com/quartznet/quartznet/blob/main/database/tables/tables_sqlServer.sql
|
|||
var configuration = context.Services.GetConfiguration(); |
|||
PreConfigure<AbpQuartzOptions>(options => |
|||
{ |
|||
options.Properties = new NameValueCollection |
|||
{ |
|||
["quartz.scheduler.instanceName"] = context.Services.GetApplicationName(), |
|||
["quartz.jobStore.dataSource"] = "BackgroundJobsDemoApp", |
|||
["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz", |
|||
["quartz.jobStore.tablePrefix"] = "QRTZ_", |
|||
["quartz.serializer.type"] = "json", |
|||
["quartz.dataSource.BackgroundJobsDemoApp.connectionString"] = configuration.GetConnectionString("Default"), |
|||
["quartz.dataSource.BackgroundJobsDemoApp.provider"] = "SqlServer", |
|||
["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz", |
|||
}; |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Quartz; |
|||
using Volo.Abp.BackgroundWorkers.Quartz; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp.Quartz2; |
|||
|
|||
public class MyLogWorker : QuartzBackgroundWorkerBase |
|||
{ |
|||
public MyLogWorker() |
|||
{ |
|||
JobDetail = JobBuilder.Create<MyLogWorker>().WithIdentity(nameof(MyLogWorker)).Build(); |
|||
Trigger = TriggerBuilder.Create().WithIdentity(nameof(MyLogWorker)).StartAt(DateTimeOffset.Now.AddSeconds(10)).Build(); |
|||
} |
|||
|
|||
public override Task Execute(IJobExecutionContext context) |
|||
{ |
|||
Console.WriteLine("Executed MyLogWorker..!"); |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
|
|||
public class MyLogWorker2 : QuartzBackgroundWorkerBase |
|||
{ |
|||
public MyLogWorker2() |
|||
{ |
|||
JobDetail = JobBuilder.Create<MyLogWorker2>().WithIdentity(nameof(MyLogWorker2)).Build(); |
|||
Trigger = TriggerBuilder.Create().WithIdentity(nameof(MyLogWorker2)).StartAt(DateTimeOffset.Now.AddSeconds(10)).Build(); |
|||
} |
|||
|
|||
public override Task Execute(IJobExecutionContext context) |
|||
{ |
|||
Console.WriteLine("Executed MyLogWorker2..!"); |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Quartz; |
|||
using Volo.Abp.BackgroundJobs.DemoApp.Shared.Jobs; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp.Quartz2; |
|||
|
|||
class Program |
|||
{ |
|||
async static Task Main(string[] args) |
|||
{ |
|||
using (var application = await AbpApplicationFactory.CreateAsync<DemoAppQuartzModule>(options => |
|||
{ |
|||
options.UseAutofac(); |
|||
})) |
|||
{ |
|||
await application.InitializeAsync(); |
|||
|
|||
await CancelableBackgroundJobAsync(application.ServiceProvider); |
|||
|
|||
Console.WriteLine("Started: " + typeof(Program).Namespace); |
|||
Console.WriteLine("Press ENTER to stop the application..!"); |
|||
Console.ReadLine(); |
|||
|
|||
await application.ShutdownAsync(); |
|||
} |
|||
} |
|||
|
|||
private async static Task CancelableBackgroundJobAsync(IServiceProvider serviceProvider) |
|||
{ |
|||
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])); |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
{} |
|||
@ -0,0 +1,73 @@ |
|||
{ |
|||
"name": "Volo.Abp.BackgroundJobs.DemoApp.Quartz", |
|||
"hash": "04c9d2c41471882c5aed1a69db51d7df", |
|||
"contents": [ |
|||
{ |
|||
"namespace": "Volo.Abp.BackgroundJobs.DemoApp.Quartz", |
|||
"dependsOnModules": [ |
|||
{ |
|||
"declaringAssemblyName": "Volo.Abp.BackgroundJobs.DemoApp.Shared", |
|||
"namespace": "Volo.Abp.BackgroundJobs.DemoApp.Shared", |
|||
"name": "DemoAppSharedModule" |
|||
}, |
|||
{ |
|||
"declaringAssemblyName": "Volo.Abp.Autofac", |
|||
"namespace": "Volo.Abp.Autofac", |
|||
"name": "AbpAutofacModule" |
|||
}, |
|||
{ |
|||
"declaringAssemblyName": "Volo.Abp.BackgroundJobs.Quartz", |
|||
"namespace": "Volo.Abp.BackgroundJobs.Quartz", |
|||
"name": "AbpBackgroundJobsQuartzModule" |
|||
} |
|||
], |
|||
"implementingInterfaces": [ |
|||
{ |
|||
"name": "IAbpModule", |
|||
"namespace": "Volo.Abp.Modularity", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.Modularity.IAbpModule" |
|||
}, |
|||
{ |
|||
"name": "IOnPreApplicationInitialization", |
|||
"namespace": "Volo.Abp.Modularity", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.Modularity.IOnPreApplicationInitialization" |
|||
}, |
|||
{ |
|||
"name": "IOnApplicationInitialization", |
|||
"namespace": "Volo.Abp", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.IOnApplicationInitialization" |
|||
}, |
|||
{ |
|||
"name": "IOnPostApplicationInitialization", |
|||
"namespace": "Volo.Abp.Modularity", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.Modularity.IOnPostApplicationInitialization" |
|||
}, |
|||
{ |
|||
"name": "IOnApplicationShutdown", |
|||
"namespace": "Volo.Abp", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.IOnApplicationShutdown" |
|||
}, |
|||
{ |
|||
"name": "IPreConfigureServices", |
|||
"namespace": "Volo.Abp.Modularity", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.Modularity.IPreConfigureServices" |
|||
}, |
|||
{ |
|||
"name": "IPostConfigureServices", |
|||
"namespace": "Volo.Abp.Modularity", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.Modularity.IPostConfigureServices" |
|||
} |
|||
], |
|||
"contentType": "abpModule", |
|||
"name": "DemoAppQuartzModule", |
|||
"summary": null |
|||
} |
|||
] |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<OutputType>Exe</OutputType> |
|||
<TargetFramework>net9.0</TargetFramework> |
|||
<RootNamespace>Volo.Abp.BackgroundJobs.DemoApp.Quartz2</RootNamespace> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Quartz.Serialization.Json" /> |
|||
<PackageReference Include="Microsoft.Data.SqlClient" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.BackgroundJobs.Quartz\Volo.Abp.BackgroundJobs.Quartz.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.BackgroundWorkers.Quartz\Volo.Abp.BackgroundWorkers.Quartz.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.BackgroundJobs.DemoApp.Shared\Volo.Abp.BackgroundJobs.DemoApp.Shared.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<None Update="appsettings.json"> |
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|||
</None> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,5 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;User Id=sa;Password=1q2w3E***;TrustServerCertificate=True" |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp.RabbitMq |
|||
{ |
|||
public class RabbitMqJob : BackgroundJob<RabbitMqJobArgs>, ITransientDependency |
|||
{ |
|||
public override void Execute(RabbitMqJobArgs args) |
|||
{ |
|||
Console.WriteLine($"[RabbitMqJob] Started: {args.Value}"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.BackgroundJobs.DemoApp.RabbitMq |
|||
{ |
|||
public class RabbitMqJobArgs |
|||
{ |
|||
public string Value { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
{ |
|||
"RabbitMQ": { |
|||
"Connections": { |
|||
"Default": { |
|||
"HostName": "localhost" |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,41 +0,0 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations; |
|||
|
|||
public partial class Initial : Migration |
|||
{ |
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.CreateTable( |
|||
name: "AbpBackgroundJobs", |
|||
columns: table => new { |
|||
Id = table.Column<Guid>(nullable: false), |
|||
ExtraProperties = table.Column<string>(nullable: true), |
|||
ConcurrencyStamp = table.Column<string>(maxLength: 40, nullable: true), |
|||
JobName = table.Column<string>(maxLength: 128, nullable: false), |
|||
JobArgs = table.Column<string>(maxLength: 1048576, nullable: false), |
|||
TryCount = table.Column<short>(nullable: false, defaultValue: (short)0), |
|||
CreationTime = table.Column<DateTime>(nullable: false), |
|||
NextTryTime = table.Column<DateTime>(nullable: false), |
|||
LastTryTime = table.Column<DateTime>(nullable: true), |
|||
IsAbandoned = table.Column<bool>(nullable: false, defaultValue: false), |
|||
Priority = table.Column<byte>(nullable: false, defaultValue: (byte)15) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_AbpBackgroundJobs", x => x.Id); |
|||
}); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_AbpBackgroundJobs_IsAbandoned_NextTryTime", |
|||
table: "AbpBackgroundJobs", |
|||
columns: new[] { "IsAbandoned", "NextTryTime" }); |
|||
} |
|||
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "AbpBackgroundJobs"); |
|||
} |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations |
|||
{ |
|||
/// <inheritdoc />
|
|||
public partial class Initial : Migration |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.CreateTable( |
|||
name: "AbpBackgroundJobs", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
ApplicationName = table.Column<string>(type: "nvarchar(96)", maxLength: 96, nullable: true), |
|||
JobName = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false), |
|||
JobArgs = table.Column<string>(type: "nvarchar(max)", maxLength: 1048576, nullable: false), |
|||
TryCount = table.Column<short>(type: "smallint", nullable: false, defaultValue: (short)0), |
|||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false), |
|||
NextTryTime = table.Column<DateTime>(type: "datetime2", nullable: false), |
|||
LastTryTime = table.Column<DateTime>(type: "datetime2", nullable: true), |
|||
IsAbandoned = table.Column<bool>(type: "bit", nullable: false, defaultValue: false), |
|||
Priority = table.Column<byte>(type: "tinyint", nullable: false, defaultValue: (byte)15), |
|||
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false), |
|||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_AbpBackgroundJobs", x => x.Id); |
|||
}); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_AbpBackgroundJobs_IsAbandoned_NextTryTime", |
|||
table: "AbpBackgroundJobs", |
|||
columns: new[] { "IsAbandoned", "NextTryTime" }); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "AbpBackgroundJobs"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.BackgroundWorkers; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp; |
|||
|
|||
public class MyWorker : BackgroundWorkerBase |
|||
{ |
|||
public override Task StartAsync(CancellationToken cancellationToken = default) |
|||
{ |
|||
Console.WriteLine("MyWorker started..!"); |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public override Task StopAsync(CancellationToken cancellationToken = default) |
|||
{ |
|||
Console.WriteLine("MyWorker stopped..!"); |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Logging; |
|||
using Volo.Abp.BackgroundWorkers; |
|||
using Volo.Abp.Threading; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp; |
|||
|
|||
public class PassiveUserCheckerWorker : AsyncPeriodicBackgroundWorkerBase |
|||
{ |
|||
public PassiveUserCheckerWorker(AbpAsyncTimer timer, IServiceScopeFactory serviceScopeFactory) |
|||
: base(timer, serviceScopeFactory) |
|||
{ |
|||
Timer.Period = 3000; //3 seconds
|
|||
} |
|||
|
|||
protected override Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext) |
|||
{ |
|||
Console.WriteLine("Starting: Setting status of inactive users..."); |
|||
Console.WriteLine("Completed: Setting status of inactive users..."); |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
@ -1,5 +1,5 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;Trusted_Connection=True;TrustServerCertificate=True" |
|||
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;User Id=sa;Password=1q2w3E***;TrustServerCertificate=True" |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,21 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.BackgroundJobs.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp2.Db; |
|||
|
|||
public class DemoAppDbContext : AbpDbContext<DemoAppDbContext> |
|||
{ |
|||
public DemoAppDbContext(DbContextOptions<DemoAppDbContext> options) |
|||
: base(options) |
|||
{ |
|||
|
|||
} |
|||
|
|||
protected override void OnModelCreating(ModelBuilder modelBuilder) |
|||
{ |
|||
base.OnModelCreating(modelBuilder); |
|||
|
|||
modelBuilder.ConfigureBackgroundJobs(); |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
using System.IO; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Design; |
|||
using Microsoft.Extensions.Configuration; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp2.Db; |
|||
|
|||
public class DemoAppDbContextFactory : IDesignTimeDbContextFactory<DemoAppDbContext> |
|||
{ |
|||
public DemoAppDbContext CreateDbContext(string[] args) |
|||
{ |
|||
var configuration = BuildConfiguration(); |
|||
|
|||
var builder = new DbContextOptionsBuilder<DemoAppDbContext>() |
|||
.UseSqlServer(configuration.GetConnectionString("Default")); |
|||
|
|||
return new DemoAppDbContext(builder.Options); |
|||
} |
|||
|
|||
private static IConfigurationRoot BuildConfiguration() |
|||
{ |
|||
var builder = new ConfigurationBuilder() |
|||
.SetBasePath(Directory.GetCurrentDirectory()) |
|||
.AddJsonFile("appsettings.json", optional: false); |
|||
|
|||
return builder.Build(); |
|||
} |
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Autofac; |
|||
using Volo.Abp.BackgroundJobs.DemoApp.Shared; |
|||
using Volo.Abp.BackgroundJobs.EntityFrameworkCore; |
|||
using Volo.Abp.BackgroundWorkers; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore.SqlServer; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp2; |
|||
|
|||
[DependsOn( |
|||
typeof(DemoAppSharedModule), |
|||
typeof(AbpBackgroundJobsEntityFrameworkCoreModule), |
|||
typeof(AbpAutofacModule), |
|||
typeof(AbpEntityFrameworkCoreSqlServerModule) |
|||
)] |
|||
public class DemoAppModule : AbpModule |
|||
{ |
|||
public override void PreConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
PreConfigure<AbpBackgroundJobWorkerOptions>(options => |
|||
{ |
|||
options.ApplicationName = context.Services.GetApplicationName()!; |
|||
}); |
|||
} |
|||
|
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
Configure<AbpDbContextOptions>(options => |
|||
{ |
|||
options.Configure(opts => |
|||
{ |
|||
opts.UseSqlServer(); |
|||
}); |
|||
}); |
|||
|
|||
Configure<AbpBackgroundJobWorkerOptions>(options => |
|||
{ |
|||
//Configure for fast running
|
|||
options.ApplicationName = context.Services.GetApplicationName()!; |
|||
options.JobPollPeriod = 1000; |
|||
options.DefaultFirstWaitDuration = 1; |
|||
options.DefaultWaitFactor = 1; |
|||
}); |
|||
} |
|||
|
|||
public async override Task OnApplicationInitializationAsync(ApplicationInitializationContext context) |
|||
{ |
|||
//TODO: Configure console logging
|
|||
//context
|
|||
// .ServiceProvider
|
|||
// .GetRequiredService<ILoggerFactory>()
|
|||
// .AddConsole(LogLevel.Debug);
|
|||
|
|||
await context.AddBackgroundWorkerAsync<MyWorker>(); |
|||
await context.AddBackgroundWorkerAsync<PassiveUserCheckerWorker>(); |
|||
} |
|||
} |
|||
@ -0,0 +1,96 @@ |
|||
// <auto-generated />
|
|||
using System; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Infrastructure; |
|||
using Microsoft.EntityFrameworkCore.Metadata; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
|||
using Volo.Abp.BackgroundJobs.DemoApp2.Db; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp2.Migrations |
|||
{ |
|||
[DbContext(typeof(DemoAppDbContext))] |
|||
[Migration("20250222094817_Initial")] |
|||
partial class Initial |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void BuildTargetModel(ModelBuilder modelBuilder) |
|||
{ |
|||
#pragma warning disable 612, 618
|
|||
modelBuilder |
|||
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.SqlServer) |
|||
.HasAnnotation("ProductVersion", "9.0.0") |
|||
.HasAnnotation("Relational:MaxIdentifierLength", 128); |
|||
|
|||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); |
|||
|
|||
modelBuilder.Entity("Volo.Abp.BackgroundJobs.BackgroundJobRecord", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.ValueGeneratedOnAdd() |
|||
.HasColumnType("uniqueidentifier"); |
|||
|
|||
b.Property<string>("ApplicationName") |
|||
.HasMaxLength(96) |
|||
.HasColumnType("nvarchar(96)"); |
|||
|
|||
b.Property<string>("ConcurrencyStamp") |
|||
.IsConcurrencyToken() |
|||
.IsRequired() |
|||
.HasMaxLength(40) |
|||
.HasColumnType("nvarchar(40)") |
|||
.HasColumnName("ConcurrencyStamp"); |
|||
|
|||
b.Property<DateTime>("CreationTime") |
|||
.HasColumnType("datetime2") |
|||
.HasColumnName("CreationTime"); |
|||
|
|||
b.Property<string>("ExtraProperties") |
|||
.IsRequired() |
|||
.HasColumnType("nvarchar(max)") |
|||
.HasColumnName("ExtraProperties"); |
|||
|
|||
b.Property<bool>("IsAbandoned") |
|||
.ValueGeneratedOnAdd() |
|||
.HasColumnType("bit") |
|||
.HasDefaultValue(false); |
|||
|
|||
b.Property<string>("JobArgs") |
|||
.IsRequired() |
|||
.HasMaxLength(1048576) |
|||
.HasColumnType("nvarchar(max)"); |
|||
|
|||
b.Property<string>("JobName") |
|||
.IsRequired() |
|||
.HasMaxLength(128) |
|||
.HasColumnType("nvarchar(128)"); |
|||
|
|||
b.Property<DateTime?>("LastTryTime") |
|||
.HasColumnType("datetime2"); |
|||
|
|||
b.Property<DateTime>("NextTryTime") |
|||
.HasColumnType("datetime2"); |
|||
|
|||
b.Property<byte>("Priority") |
|||
.ValueGeneratedOnAdd() |
|||
.HasColumnType("tinyint") |
|||
.HasDefaultValue((byte)15); |
|||
|
|||
b.Property<short>("TryCount") |
|||
.ValueGeneratedOnAdd() |
|||
.HasColumnType("smallint") |
|||
.HasDefaultValue((short)0); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.HasIndex("IsAbandoned", "NextTryTime"); |
|||
|
|||
b.ToTable("AbpBackgroundJobs", (string)null); |
|||
}); |
|||
#pragma warning restore 612, 618
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp2.Migrations |
|||
{ |
|||
/// <inheritdoc />
|
|||
public partial class Initial : Migration |
|||
{ |
|||
/// <inheritdoc />
|
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.CreateTable( |
|||
name: "AbpBackgroundJobs", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
ApplicationName = table.Column<string>(type: "nvarchar(96)", maxLength: 96, nullable: true), |
|||
JobName = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false), |
|||
JobArgs = table.Column<string>(type: "nvarchar(max)", maxLength: 1048576, nullable: false), |
|||
TryCount = table.Column<short>(type: "smallint", nullable: false, defaultValue: (short)0), |
|||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false), |
|||
NextTryTime = table.Column<DateTime>(type: "datetime2", nullable: false), |
|||
LastTryTime = table.Column<DateTime>(type: "datetime2", nullable: true), |
|||
IsAbandoned = table.Column<bool>(type: "bit", nullable: false, defaultValue: false), |
|||
Priority = table.Column<byte>(type: "tinyint", nullable: false, defaultValue: (byte)15), |
|||
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false), |
|||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_AbpBackgroundJobs", x => x.Id); |
|||
}); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_AbpBackgroundJobs_IsAbandoned_NextTryTime", |
|||
table: "AbpBackgroundJobs", |
|||
columns: new[] { "IsAbandoned", "NextTryTime" }); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "AbpBackgroundJobs"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,93 @@ |
|||
// <auto-generated />
|
|||
using System; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Infrastructure; |
|||
using Microsoft.EntityFrameworkCore.Metadata; |
|||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
|||
using Volo.Abp.BackgroundJobs.DemoApp2.Db; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp2.Migrations |
|||
{ |
|||
[DbContext(typeof(DemoAppDbContext))] |
|||
partial class DemoAppDbContextModelSnapshot : ModelSnapshot |
|||
{ |
|||
protected override void BuildModel(ModelBuilder modelBuilder) |
|||
{ |
|||
#pragma warning disable 612, 618
|
|||
modelBuilder |
|||
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.SqlServer) |
|||
.HasAnnotation("ProductVersion", "9.0.0") |
|||
.HasAnnotation("Relational:MaxIdentifierLength", 128); |
|||
|
|||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); |
|||
|
|||
modelBuilder.Entity("Volo.Abp.BackgroundJobs.BackgroundJobRecord", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.ValueGeneratedOnAdd() |
|||
.HasColumnType("uniqueidentifier"); |
|||
|
|||
b.Property<string>("ApplicationName") |
|||
.HasMaxLength(96) |
|||
.HasColumnType("nvarchar(96)"); |
|||
|
|||
b.Property<string>("ConcurrencyStamp") |
|||
.IsConcurrencyToken() |
|||
.IsRequired() |
|||
.HasMaxLength(40) |
|||
.HasColumnType("nvarchar(40)") |
|||
.HasColumnName("ConcurrencyStamp"); |
|||
|
|||
b.Property<DateTime>("CreationTime") |
|||
.HasColumnType("datetime2") |
|||
.HasColumnName("CreationTime"); |
|||
|
|||
b.Property<string>("ExtraProperties") |
|||
.IsRequired() |
|||
.HasColumnType("nvarchar(max)") |
|||
.HasColumnName("ExtraProperties"); |
|||
|
|||
b.Property<bool>("IsAbandoned") |
|||
.ValueGeneratedOnAdd() |
|||
.HasColumnType("bit") |
|||
.HasDefaultValue(false); |
|||
|
|||
b.Property<string>("JobArgs") |
|||
.IsRequired() |
|||
.HasMaxLength(1048576) |
|||
.HasColumnType("nvarchar(max)"); |
|||
|
|||
b.Property<string>("JobName") |
|||
.IsRequired() |
|||
.HasMaxLength(128) |
|||
.HasColumnType("nvarchar(128)"); |
|||
|
|||
b.Property<DateTime?>("LastTryTime") |
|||
.HasColumnType("datetime2"); |
|||
|
|||
b.Property<DateTime>("NextTryTime") |
|||
.HasColumnType("datetime2"); |
|||
|
|||
b.Property<byte>("Priority") |
|||
.ValueGeneratedOnAdd() |
|||
.HasColumnType("tinyint") |
|||
.HasDefaultValue((byte)15); |
|||
|
|||
b.Property<short>("TryCount") |
|||
.ValueGeneratedOnAdd() |
|||
.HasColumnType("smallint") |
|||
.HasDefaultValue((short)0); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.HasIndex("IsAbandoned", "NextTryTime"); |
|||
|
|||
b.ToTable("AbpBackgroundJobs", (string)null); |
|||
}); |
|||
#pragma warning restore 612, 618
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.BackgroundWorkers; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp2; |
|||
|
|||
public class MyWorker : BackgroundWorkerBase |
|||
{ |
|||
public override Task StartAsync(CancellationToken cancellationToken = default) |
|||
{ |
|||
Console.WriteLine("MyWorker started..!"); |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public override Task StopAsync(CancellationToken cancellationToken = default) |
|||
{ |
|||
Console.WriteLine("MyWorker stopped..!"); |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.BackgroundWorkers; |
|||
using Volo.Abp.Threading; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp2; |
|||
|
|||
public class PassiveUserCheckerWorker : AsyncPeriodicBackgroundWorkerBase |
|||
{ |
|||
public PassiveUserCheckerWorker(AbpAsyncTimer timer, IServiceScopeFactory serviceScopeFactory) |
|||
: base(timer, serviceScopeFactory) |
|||
{ |
|||
Timer.Period = 3000; //3 seconds
|
|||
} |
|||
|
|||
protected override Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext) |
|||
{ |
|||
Console.WriteLine("Starting: Setting status of inactive users..."); |
|||
Console.WriteLine("Completed: Setting status of inactive users..."); |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.DemoApp2; |
|||
|
|||
class Program |
|||
{ |
|||
async static Task Main(string[] args) |
|||
{ |
|||
using (var application = await AbpApplicationFactory.CreateAsync<DemoAppModule>(options => |
|||
{ |
|||
options.UseAutofac(); |
|||
})) |
|||
{ |
|||
await application.InitializeAsync(); |
|||
|
|||
Console.WriteLine("Started: " + typeof(Program).Namespace); |
|||
Console.WriteLine("Press ENTER to stop the application..!"); |
|||
Console.ReadLine(); |
|||
|
|||
await application.ShutdownAsync(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
{} |
|||
@ -0,0 +1,78 @@ |
|||
{ |
|||
"name": "Volo.Abp.BackgroundJobs.DemoApp", |
|||
"hash": "9ef6206e41d1a33e5255974ae2b57ad0", |
|||
"contents": [ |
|||
{ |
|||
"namespace": "Volo.Abp.BackgroundJobs.DemoApp", |
|||
"dependsOnModules": [ |
|||
{ |
|||
"declaringAssemblyName": "Volo.Abp.BackgroundJobs.DemoApp.Shared", |
|||
"namespace": "Volo.Abp.BackgroundJobs.DemoApp.Shared", |
|||
"name": "DemoAppSharedModule" |
|||
}, |
|||
{ |
|||
"declaringAssemblyName": "Volo.Abp.BackgroundJobs.EntityFrameworkCore", |
|||
"namespace": "Volo.Abp.BackgroundJobs.EntityFrameworkCore", |
|||
"name": "AbpBackgroundJobsEntityFrameworkCoreModule" |
|||
}, |
|||
{ |
|||
"declaringAssemblyName": "Volo.Abp.Autofac", |
|||
"namespace": "Volo.Abp.Autofac", |
|||
"name": "AbpAutofacModule" |
|||
}, |
|||
{ |
|||
"declaringAssemblyName": "Volo.Abp.EntityFrameworkCore.SqlServer", |
|||
"namespace": "Volo.Abp.EntityFrameworkCore.SqlServer", |
|||
"name": "AbpEntityFrameworkCoreSqlServerModule" |
|||
} |
|||
], |
|||
"implementingInterfaces": [ |
|||
{ |
|||
"name": "IAbpModule", |
|||
"namespace": "Volo.Abp.Modularity", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.Modularity.IAbpModule" |
|||
}, |
|||
{ |
|||
"name": "IOnPreApplicationInitialization", |
|||
"namespace": "Volo.Abp.Modularity", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.Modularity.IOnPreApplicationInitialization" |
|||
}, |
|||
{ |
|||
"name": "IOnApplicationInitialization", |
|||
"namespace": "Volo.Abp", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.IOnApplicationInitialization" |
|||
}, |
|||
{ |
|||
"name": "IOnPostApplicationInitialization", |
|||
"namespace": "Volo.Abp.Modularity", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.Modularity.IOnPostApplicationInitialization" |
|||
}, |
|||
{ |
|||
"name": "IOnApplicationShutdown", |
|||
"namespace": "Volo.Abp", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.IOnApplicationShutdown" |
|||
}, |
|||
{ |
|||
"name": "IPreConfigureServices", |
|||
"namespace": "Volo.Abp.Modularity", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.Modularity.IPreConfigureServices" |
|||
}, |
|||
{ |
|||
"name": "IPostConfigureServices", |
|||
"namespace": "Volo.Abp.Modularity", |
|||
"declaringAssemblyName": "Volo.Abp.Core", |
|||
"fullName": "Volo.Abp.Modularity.IPostConfigureServices" |
|||
} |
|||
], |
|||
"contentType": "abpModule", |
|||
"name": "DemoAppModule", |
|||
"summary": null |
|||
} |
|||
] |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<OutputType>Exe</OutputType> |
|||
<TargetFramework>net9.0</TargetFramework> |
|||
<RootNamespace>Volo.Abp.BackgroundJobs.DemoApp2</RootNamespace> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools"> |
|||
<PrivateAssets>all</PrivateAssets> |
|||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> |
|||
</PackageReference> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.EntityFrameworkCore.SqlServer\Volo.Abp.EntityFrameworkCore.SqlServer.csproj" /> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.BackgroundJobs.EntityFrameworkCore\Volo.Abp.BackgroundJobs.EntityFrameworkCore.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.BackgroundJobs.DemoApp.Shared\Volo.Abp.BackgroundJobs.DemoApp.Shared.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<None Update="appsettings.json"> |
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|||
</None> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,5 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;User Id=sa;Password=1q2w3E***;TrustServerCertificate=True" |
|||
} |
|||
} |
|||
Loading…
Reference in new issue