Browse Source

Change `BackgroundJobs.DemoApp` for testing.

BackgroundJob-ApplicationName-Test
maliming 12 months ago
parent
commit
d43b3a985e
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 21
      modules/background-jobs/Volo.Abp.BackgroundJobs.sln
  2. 37
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/DemoAppHangfireModule.cs
  3. 38
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/MyLogWorker.cs
  4. 2
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/Volo.Abp.BackgroundJobs.DemoApp.HangFire.csproj
  5. 2
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/appsettings.json
  6. 54
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire2/DemoAppHangfireModule.cs
  7. 38
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire2/MyLogWorker.cs
  8. 39
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire2/Program.cs
  9. 1
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire2/Volo.Abp.BackgroundJobs.DemoApp.HangFire.abppkg
  10. 73
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire2/Volo.Abp.BackgroundJobs.DemoApp.HangFire.abppkg.analyze.json
  11. 24
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire2/Volo.Abp.BackgroundJobs.DemoApp.HangFire2.csproj
  12. 5
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire2/appsettings.json
  13. 30
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz/DemoAppQuartzModule.cs
  14. 36
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz/MyLogWorker.cs
  15. 8
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz/Volo.Abp.BackgroundJobs.DemoApp.Quartz.csproj
  16. 5
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz/appsettings.json
  17. 40
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz2/DemoAppQuartzModule.cs
  18. 36
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz2/MyLogWorker.cs
  19. 40
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz2/Program.cs
  20. 1
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz2/Volo.Abp.BackgroundJobs.DemoApp.Quartz.abppkg
  21. 73
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz2/Volo.Abp.BackgroundJobs.DemoApp.Quartz.abppkg.analyze.json
  22. 27
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz2/Volo.Abp.BackgroundJobs.DemoApp.Quartz2.csproj
  23. 5
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz2/appsettings.json
  24. 18
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.RabbitMq/DemoAppRabbitMqModule.cs
  25. 13
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.RabbitMq/RabbitMqJob.cs
  26. 7
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.RabbitMq/RabbitMqJobArgs.cs
  27. 9
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.RabbitMq/appsettings.json
  28. 16
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/DemoAppModule.cs
  29. 41
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20201013055401_Initial.cs
  30. 40
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20250222094840_Initial.Designer.cs
  31. 49
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20250222094840_Initial.cs
  32. 37
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/DemoAppDbContextModelSnapshot.cs
  33. 21
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/MyWorker.cs
  34. 24
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/PassiveUserCheckerWorker.cs
  35. 1
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Volo.Abp.BackgroundJobs.DemoApp.csproj
  36. 4
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/appsettings.json
  37. 21
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/Db/DemoAppDbContext.cs
  38. 28
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/Db/DemoAppDbContextFactory.cs
  39. 60
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/DemoAppModule.cs
  40. 96
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/Migrations/20250222094817_Initial.Designer.cs
  41. 49
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/Migrations/20250222094817_Initial.cs
  42. 93
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/Migrations/DemoAppDbContextModelSnapshot.cs
  43. 21
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/MyWorker.cs
  44. 23
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/PassiveUserCheckerWorker.cs
  45. 24
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/Program.cs
  46. 1
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/Volo.Abp.BackgroundJobs.DemoApp.abppkg
  47. 78
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/Volo.Abp.BackgroundJobs.DemoApp.abppkg.analyze.json
  48. 26
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/Volo.Abp.BackgroundJobs.DemoApp2.csproj
  49. 5
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/appsettings.json

21
modules/background-jobs/Volo.Abp.BackgroundJobs.sln

@ -37,6 +37,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BackgroundJobs.Dem
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BackgroundJobs.Installer", "src\Volo.Abp.BackgroundJobs.Installer\Volo.Abp.BackgroundJobs.Installer.csproj", "{FCD1EFC7-28D6-40F5-8C9A-7DE0328D6758}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BackgroundJobs.Installer", "src\Volo.Abp.BackgroundJobs.Installer\Volo.Abp.BackgroundJobs.Installer.csproj", "{FCD1EFC7-28D6-40F5-8C9A-7DE0328D6758}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BackgroundJobs.DemoApp.HangFire2", "app\Volo.Abp.BackgroundJobs.DemoApp.HangFire2\Volo.Abp.BackgroundJobs.DemoApp.HangFire2.csproj", "{64C96E97-AF98-40A0-94D8-6C21106EA4B0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BackgroundJobs.DemoApp.Quartz2", "app\Volo.Abp.BackgroundJobs.DemoApp.Quartz2\Volo.Abp.BackgroundJobs.DemoApp.Quartz2.csproj", "{7D897239-0D45-4A35-9CF7-0093F1AFD0E9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BackgroundJobs.DemoApp2", "app\Volo.Abp.BackgroundJobs.DemoApp2\Volo.Abp.BackgroundJobs.DemoApp2.csproj", "{0CADE59C-72C6-4860-A382-A515291D43A4}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -99,6 +105,18 @@ Global
{FCD1EFC7-28D6-40F5-8C9A-7DE0328D6758}.Debug|Any CPU.Build.0 = Debug|Any CPU {FCD1EFC7-28D6-40F5-8C9A-7DE0328D6758}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FCD1EFC7-28D6-40F5-8C9A-7DE0328D6758}.Release|Any CPU.ActiveCfg = Release|Any CPU {FCD1EFC7-28D6-40F5-8C9A-7DE0328D6758}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FCD1EFC7-28D6-40F5-8C9A-7DE0328D6758}.Release|Any CPU.Build.0 = Release|Any CPU {FCD1EFC7-28D6-40F5-8C9A-7DE0328D6758}.Release|Any CPU.Build.0 = Release|Any CPU
{64C96E97-AF98-40A0-94D8-6C21106EA4B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{64C96E97-AF98-40A0-94D8-6C21106EA4B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64C96E97-AF98-40A0-94D8-6C21106EA4B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64C96E97-AF98-40A0-94D8-6C21106EA4B0}.Release|Any CPU.Build.0 = Release|Any CPU
{7D897239-0D45-4A35-9CF7-0093F1AFD0E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D897239-0D45-4A35-9CF7-0093F1AFD0E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D897239-0D45-4A35-9CF7-0093F1AFD0E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D897239-0D45-4A35-9CF7-0093F1AFD0E9}.Release|Any CPU.Build.0 = Release|Any CPU
{0CADE59C-72C6-4860-A382-A515291D43A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0CADE59C-72C6-4860-A382-A515291D43A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0CADE59C-72C6-4860-A382-A515291D43A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0CADE59C-72C6-4860-A382-A515291D43A4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -118,6 +136,9 @@ Global
{7C8D03F7-165E-478C-A6D6-DC8229EEABB9} = {E400416D-2895-4512-9D17-90681EEC7E0A} {7C8D03F7-165E-478C-A6D6-DC8229EEABB9} = {E400416D-2895-4512-9D17-90681EEC7E0A}
{0146891D-3FF8-4516-94D6-B9EFC37383CD} = {E400416D-2895-4512-9D17-90681EEC7E0A} {0146891D-3FF8-4516-94D6-B9EFC37383CD} = {E400416D-2895-4512-9D17-90681EEC7E0A}
{FCD1EFC7-28D6-40F5-8C9A-7DE0328D6758} = {649A3FFA-182F-4E56-9717-E6A9A2BEC545} {FCD1EFC7-28D6-40F5-8C9A-7DE0328D6758} = {649A3FFA-182F-4E56-9717-E6A9A2BEC545}
{64C96E97-AF98-40A0-94D8-6C21106EA4B0} = {E400416D-2895-4512-9D17-90681EEC7E0A}
{7D897239-0D45-4A35-9CF7-0093F1AFD0E9} = {E400416D-2895-4512-9D17-90681EEC7E0A}
{0CADE59C-72C6-4860-A382-A515291D43A4} = {E400416D-2895-4512-9D17-90681EEC7E0A}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4324B3B4-B60B-4E3C-91D8-59576B4E26DD} SolutionGuid = {4324B3B4-B60B-4E3C-91D8-59576B4E26DD}

37
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/DemoAppHangfireModule.cs

@ -1,17 +1,22 @@
using Hangfire; using System.Threading.Tasks;
using Hangfire;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Autofac; using Volo.Abp.Autofac;
using Volo.Abp.BackgroundJobs.DemoApp.Shared; using Volo.Abp.BackgroundJobs.DemoApp.Shared;
using Volo.Abp.Modularity;
using Microsoft.Extensions.Configuration;
using Volo.Abp.BackgroundJobs.Hangfire; 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.HangFire; namespace Volo.Abp.BackgroundJobs.DemoApp.HangFire;
[DependsOn( [DependsOn(
typeof(DemoAppSharedModule), typeof(DemoAppSharedModule),
typeof(AbpAutofacModule), typeof(AbpAutofacModule),
typeof(AbpBackgroundJobsHangfireModule) typeof(AbpBackgroundJobsHangfireModule),
typeof(AbpBackgroundWorkersHangfireModule)
)] )]
public class DemoAppHangfireModule : AbpModule public class DemoAppHangfireModule : AbpModule
{ {
@ -19,9 +24,31 @@ public class DemoAppHangfireModule : AbpModule
{ {
var configuration = context.Services.GetConfiguration(); var configuration = context.Services.GetConfiguration();
context.Services.PreConfigure<IGlobalConfiguration>(hangfireConfiguration => PreConfigure<IGlobalConfiguration>(hangfireConfiguration =>
{ {
hangfireConfiguration.UseSqlServerStorage(configuration.GetConnectionString("Default")); 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>();
}
} }

38
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/MyLogWorker.cs

@ -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;
}
}

2
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/Volo.Abp.BackgroundJobs.DemoApp.HangFire.csproj

@ -7,8 +7,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Hangfire.SqlServer" /> <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.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.BackgroundJobs.HangFire\Volo.Abp.BackgroundJobs.HangFire.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" /> <ProjectReference Include="..\Volo.Abp.BackgroundJobs.DemoApp.Shared\Volo.Abp.BackgroundJobs.DemoApp.Shared.csproj" />
</ItemGroup> </ItemGroup>

2
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/appsettings.json

@ -1,5 +1,5 @@
{ {
"ConnectionStrings": { "ConnectionStrings": {
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;Trusted_Connection=True;TrustServerCertificate=True" "Default": "Server=localhost;Database=BackgroundJobsDemoApp;User Id=sa;Password=1q2w3E***;TrustServerCertificate=True"
} }
} }

54
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire2/DemoAppHangfireModule.cs

@ -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>();
}
}

38
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire2/MyLogWorker.cs

@ -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;
}
}

39
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire2/Program.cs

@ -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);
}
}

1
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire2/Volo.Abp.BackgroundJobs.DemoApp.HangFire.abppkg

@ -0,0 +1 @@
{}

73
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire2/Volo.Abp.BackgroundJobs.DemoApp.HangFire.abppkg.analyze.json

@ -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
}
]
}

24
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire2/Volo.Abp.BackgroundJobs.DemoApp.HangFire2.csproj

@ -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>

5
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire2/appsettings.json

@ -0,0 +1,5 @@
{
"ConnectionStrings": {
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;User Id=sa;Password=1q2w3E***;TrustServerCertificate=True"
}
}

30
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz/DemoAppQuartzModule.cs

@ -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.DemoApp.Shared;
using Volo.Abp.BackgroundJobs.Quartz; using Volo.Abp.BackgroundJobs.Quartz;
using Volo.Abp.BackgroundWorkers.Quartz;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.Quartz;
namespace Volo.Abp.BackgroundJobs.DemoApp.Quartz; namespace Volo.Abp.BackgroundJobs.DemoApp.Quartz;
[DependsOn( [DependsOn(
typeof(DemoAppSharedModule), typeof(DemoAppSharedModule),
typeof(AbpAutofacModule), typeof(AbpAutofacModule),
typeof(AbpBackgroundJobsQuartzModule) typeof(AbpBackgroundJobsQuartzModule),
typeof(AbpBackgroundWorkersQuartzModule)
)] )]
public class DemoAppQuartzModule : AbpModule 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",
};
});
}
} }

36
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz/MyLogWorker.cs

@ -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;
}
}

8
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz/Volo.Abp.BackgroundJobs.DemoApp.Quartz.csproj

@ -7,12 +7,20 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Quartz.Serialization.Json" /> <PackageReference Include="Quartz.Serialization.Json" />
<PackageReference Include="Microsoft.Data.SqlClient" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> <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.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" /> <ProjectReference Include="..\Volo.Abp.BackgroundJobs.DemoApp.Shared\Volo.Abp.BackgroundJobs.DemoApp.Shared.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>

5
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz/appsettings.json

@ -0,0 +1,5 @@
{
"ConnectionStrings": {
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;User Id=sa;Password=1q2w3E***;TrustServerCertificate=True"
}
}

40
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz2/DemoAppQuartzModule.cs

@ -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",
};
});
}
}

36
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz2/MyLogWorker.cs

@ -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;
}
}

40
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz2/Program.cs

@ -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]));
}
}

1
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz2/Volo.Abp.BackgroundJobs.DemoApp.Quartz.abppkg

@ -0,0 +1 @@
{}

73
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz2/Volo.Abp.BackgroundJobs.DemoApp.Quartz.abppkg.analyze.json

@ -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
}
]
}

27
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz2/Volo.Abp.BackgroundJobs.DemoApp.Quartz2.csproj

@ -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>

5
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz2/appsettings.json

@ -0,0 +1,5 @@
{
"ConnectionStrings": {
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;User Id=sa;Password=1q2w3E***;TrustServerCertificate=True"
}
}

18
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.RabbitMq/DemoAppRabbitMqModule.cs

@ -1,5 +1,8 @@
using Volo.Abp.Autofac; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Autofac;
using Volo.Abp.BackgroundJobs.DemoApp.Shared; using Volo.Abp.BackgroundJobs.DemoApp.Shared;
using Volo.Abp.BackgroundJobs.DemoApp.Shared.Jobs;
using Volo.Abp.BackgroundJobs.RabbitMQ; using Volo.Abp.BackgroundJobs.RabbitMQ;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
@ -12,5 +15,18 @@ namespace Volo.Abp.BackgroundJobs.DemoApp.RabbitMq;
)] )]
public class DemoAppRabbitMqModule : AbpModule public class DemoAppRabbitMqModule : AbpModule
{ {
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<AbpRabbitMqBackgroundJobOptions>(options =>
{
options.DefaultQueueNamePrefix = context.Services.GetApplicationName()!.EndsWith('.') + options.DefaultQueueNamePrefix;
options.DefaultDelayedQueueNamePrefix = context.Services.GetApplicationName()!.EndsWith('.') + options.DefaultDelayedQueueNamePrefix;
});
}
public async override Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
{
var jobManager = context.ServiceProvider.GetRequiredService<IBackgroundJobManager>();
await jobManager.EnqueueAsync(new RabbitMqJobArgs() { Value = "test 1 (rabbitmq)" });
}
} }

13
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.RabbitMq/RabbitMqJob.cs

@ -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}");
}
}
}

7
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.RabbitMq/RabbitMqJobArgs.cs

@ -0,0 +1,7 @@
namespace Volo.Abp.BackgroundJobs.DemoApp.RabbitMq
{
public class RabbitMqJobArgs
{
public string Value { get; set; }
}
}

9
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.RabbitMq/appsettings.json

@ -0,0 +1,9 @@
{
"RabbitMQ": {
"Connections": {
"Default": {
"HostName": "localhost"
}
}
}
}

16
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/DemoAppModule.cs

@ -1,7 +1,9 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Autofac; using Volo.Abp.Autofac;
using Volo.Abp.BackgroundJobs.DemoApp.Shared; using Volo.Abp.BackgroundJobs.DemoApp.Shared;
using Volo.Abp.BackgroundJobs.EntityFrameworkCore; using Volo.Abp.BackgroundJobs.EntityFrameworkCore;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.SqlServer; using Volo.Abp.EntityFrameworkCore.SqlServer;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
@ -16,6 +18,14 @@ namespace Volo.Abp.BackgroundJobs.DemoApp;
)] )]
public class DemoAppModule : AbpModule public class DemoAppModule : AbpModule
{ {
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<AbpBackgroundJobWorkerOptions>(options =>
{
options.ApplicationName = context.Services.GetApplicationName()!;
});
}
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
{ {
Configure<AbpDbContextOptions>(options => Configure<AbpDbContextOptions>(options =>
@ -29,13 +39,14 @@ public class DemoAppModule : AbpModule
Configure<AbpBackgroundJobWorkerOptions>(options => Configure<AbpBackgroundJobWorkerOptions>(options =>
{ {
//Configure for fast running //Configure for fast running
options.ApplicationName = context.Services.GetApplicationName()!;
options.JobPollPeriod = 1000; options.JobPollPeriod = 1000;
options.DefaultFirstWaitDuration = 1; options.DefaultFirstWaitDuration = 1;
options.DefaultWaitFactor = 1; options.DefaultWaitFactor = 1;
}); });
} }
public override Task OnApplicationInitializationAsync(ApplicationInitializationContext context) public async override Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
{ {
//TODO: Configure console logging //TODO: Configure console logging
//context //context
@ -43,6 +54,7 @@ public class DemoAppModule : AbpModule
// .GetRequiredService<ILoggerFactory>() // .GetRequiredService<ILoggerFactory>()
// .AddConsole(LogLevel.Debug); // .AddConsole(LogLevel.Debug);
return Task.CompletedTask; await context.AddBackgroundWorkerAsync<MyWorker>();
await context.AddBackgroundWorkerAsync<PassiveUserCheckerWorker>();
} }
} }

41
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20201013055401_Initial.cs

@ -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");
}
}

40
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20201013055401_Initial.Designer.cs → modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20250222094840_Initial.Designer.cs

@ -8,20 +8,24 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Volo.Abp.BackgroundJobs.DemoApp.Db; using Volo.Abp.BackgroundJobs.DemoApp.Db;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
#nullable disable
namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations
{ {
[DbContext(typeof(DemoAppDbContext))] [DbContext(typeof(DemoAppDbContext))]
[Migration("20201013055401_Initial")] [Migration("20250222094840_Initial")]
partial class Initial partial class Initial
{ {
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
{ {
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder modelBuilder
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.SqlServer) .HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.SqlServer)
.HasAnnotation("ProductVersion", "3.1.8") .HasAnnotation("ProductVersion", "9.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("Relational:MaxIdentifierLength", 128);
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("Volo.Abp.BackgroundJobs.BackgroundJobRecord", b => modelBuilder.Entity("Volo.Abp.BackgroundJobs.BackgroundJobRecord", b =>
{ {
@ -29,19 +33,25 @@ namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier"); .HasColumnType("uniqueidentifier");
b.Property<string>("ApplicationName")
.HasMaxLength(96)
.HasColumnType("nvarchar(96)");
b.Property<string>("ConcurrencyStamp") b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken() .IsConcurrencyToken()
.HasColumnName("ConcurrencyStamp") .IsRequired()
.HasMaxLength(40)
.HasColumnType("nvarchar(40)") .HasColumnType("nvarchar(40)")
.HasMaxLength(40); .HasColumnName("ConcurrencyStamp");
b.Property<DateTime>("CreationTime") b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime") .HasColumnType("datetime2")
.HasColumnType("datetime2"); .HasColumnName("CreationTime");
b.Property<string>("ExtraProperties") b.Property<string>("ExtraProperties")
.HasColumnName("ExtraProperties") .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)")
.HasColumnName("ExtraProperties");
b.Property<bool>("IsAbandoned") b.Property<bool>("IsAbandoned")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -50,13 +60,13 @@ namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations
b.Property<string>("JobArgs") b.Property<string>("JobArgs")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)") .HasMaxLength(1048576)
.HasMaxLength(1048576); .HasColumnType("nvarchar(max)");
b.Property<string>("JobName") b.Property<string>("JobName")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(128)") .HasMaxLength(128)
.HasMaxLength(128); .HasColumnType("nvarchar(128)");
b.Property<DateTime?>("LastTryTime") b.Property<DateTime?>("LastTryTime")
.HasColumnType("datetime2"); .HasColumnType("datetime2");
@ -78,7 +88,7 @@ namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations
b.HasIndex("IsAbandoned", "NextTryTime"); b.HasIndex("IsAbandoned", "NextTryTime");
b.ToTable("AbpBackgroundJobs"); b.ToTable("AbpBackgroundJobs", (string)null);
}); });
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }

49
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20250222094840_Initial.cs

@ -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");
}
}
}

37
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/DemoAppDbContextModelSnapshot.cs

@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Volo.Abp.BackgroundJobs.DemoApp.Db; using Volo.Abp.BackgroundJobs.DemoApp.Db;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
#nullable disable
namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations
{ {
[DbContext(typeof(DemoAppDbContext))] [DbContext(typeof(DemoAppDbContext))]
@ -17,9 +19,10 @@ namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder modelBuilder
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.SqlServer) .HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.SqlServer)
.HasAnnotation("ProductVersion", "3.1.8") .HasAnnotation("ProductVersion", "9.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("Relational:MaxIdentifierLength", 128);
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("Volo.Abp.BackgroundJobs.BackgroundJobRecord", b => modelBuilder.Entity("Volo.Abp.BackgroundJobs.BackgroundJobRecord", b =>
{ {
@ -27,19 +30,25 @@ namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier"); .HasColumnType("uniqueidentifier");
b.Property<string>("ApplicationName")
.HasMaxLength(96)
.HasColumnType("nvarchar(96)");
b.Property<string>("ConcurrencyStamp") b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken() .IsConcurrencyToken()
.HasColumnName("ConcurrencyStamp") .IsRequired()
.HasMaxLength(40)
.HasColumnType("nvarchar(40)") .HasColumnType("nvarchar(40)")
.HasMaxLength(40); .HasColumnName("ConcurrencyStamp");
b.Property<DateTime>("CreationTime") b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime") .HasColumnType("datetime2")
.HasColumnType("datetime2"); .HasColumnName("CreationTime");
b.Property<string>("ExtraProperties") b.Property<string>("ExtraProperties")
.HasColumnName("ExtraProperties") .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)")
.HasColumnName("ExtraProperties");
b.Property<bool>("IsAbandoned") b.Property<bool>("IsAbandoned")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -48,13 +57,13 @@ namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations
b.Property<string>("JobArgs") b.Property<string>("JobArgs")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)") .HasMaxLength(1048576)
.HasMaxLength(1048576); .HasColumnType("nvarchar(max)");
b.Property<string>("JobName") b.Property<string>("JobName")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(128)") .HasMaxLength(128)
.HasMaxLength(128); .HasColumnType("nvarchar(128)");
b.Property<DateTime?>("LastTryTime") b.Property<DateTime?>("LastTryTime")
.HasColumnType("datetime2"); .HasColumnType("datetime2");
@ -76,7 +85,7 @@ namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations
b.HasIndex("IsAbandoned", "NextTryTime"); b.HasIndex("IsAbandoned", "NextTryTime");
b.ToTable("AbpBackgroundJobs"); b.ToTable("AbpBackgroundJobs", (string)null);
}); });
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }

21
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/MyWorker.cs

@ -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;
}
}

24
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/PassiveUserCheckerWorker.cs

@ -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
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Volo.Abp.BackgroundJobs.DemoApp.csproj

@ -3,6 +3,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<RootNamespace>Volo.Abp.BackgroundJobs.DemoApp</RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

4
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/appsettings.json

@ -1,5 +1,5 @@
{ {
"ConnectionStrings": { "ConnectionStrings": {
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;Trusted_Connection=True;TrustServerCertificate=True" "Default": "Server=localhost;Database=BackgroundJobsDemoApp;User Id=sa;Password=1q2w3E***;TrustServerCertificate=True"
} }
} }

21
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/Db/DemoAppDbContext.cs

@ -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();
}
}

28
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/Db/DemoAppDbContextFactory.cs

@ -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();
}
}

60
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/DemoAppModule.cs

@ -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>();
}
}

96
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/Migrations/20250222094817_Initial.Designer.cs

@ -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
}
}
}

49
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/Migrations/20250222094817_Initial.cs

@ -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");
}
}
}

93
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/Migrations/DemoAppDbContextModelSnapshot.cs

@ -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
}
}
}

21
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/MyWorker.cs

@ -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;
}
}

23
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/PassiveUserCheckerWorker.cs

@ -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;
}
}

24
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/Program.cs

@ -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();
}
}
}

1
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/Volo.Abp.BackgroundJobs.DemoApp.abppkg

@ -0,0 +1 @@
{}

78
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/Volo.Abp.BackgroundJobs.DemoApp.abppkg.analyze.json

@ -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
}
]
}

26
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/Volo.Abp.BackgroundJobs.DemoApp2.csproj

@ -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>

5
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp2/appsettings.json

@ -0,0 +1,5 @@
{
"ConnectionStrings": {
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;User Id=sa;Password=1q2w3E***;TrustServerCertificate=True"
}
}
Loading…
Cancel
Save