diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/DemoAppHangfireModule.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/DemoAppHangfireModule.cs index 0a405d4767..cd74c10f82 100644 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/DemoAppHangfireModule.cs +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/DemoAppHangfireModule.cs @@ -6,23 +6,22 @@ using Volo.Abp.Modularity; using Microsoft.Extensions.Configuration; using Volo.Abp.BackgroundJobs.Hangfire; -namespace Volo.Abp.BackgroundJobs.DemoApp.HangFire +namespace Volo.Abp.BackgroundJobs.DemoApp.HangFire; + +[DependsOn( + typeof(DemoAppSharedModule), + typeof(AbpAutofacModule), + typeof(AbpBackgroundJobsHangfireModule) +)] +public class DemoAppHangfireModule : AbpModule { - [DependsOn( - typeof(DemoAppSharedModule), - typeof(AbpAutofacModule), - typeof(AbpBackgroundJobsHangfireModule) - )] - public class DemoAppHangfireModule : AbpModule + public override void PreConfigureServices(ServiceConfigurationContext context) { - public override void PreConfigureServices(ServiceConfigurationContext context) - { - var configuration = context.Services.GetConfiguration(); + var configuration = context.Services.GetConfiguration(); - context.Services.PreConfigure(hangfireConfiguration => - { - hangfireConfiguration.UseSqlServerStorage(configuration.GetConnectionString("Default")); - }); - } + context.Services.PreConfigure(hangfireConfiguration => + { + hangfireConfiguration.UseSqlServerStorage(configuration.GetConnectionString("Default")); + }); } } diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/Program.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/Program.cs index 00781d38f6..5f2c23ceb4 100644 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/Program.cs +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/Program.cs @@ -1,24 +1,23 @@ using System; -namespace Volo.Abp.BackgroundJobs.DemoApp.HangFire +namespace Volo.Abp.BackgroundJobs.DemoApp.HangFire; + +class Program { - class Program + static void Main(string[] args) { - static void Main(string[] args) + using (var application = AbpApplicationFactory.Create(options => + { + options.UseAutofac(); + })) { - using (var application = AbpApplicationFactory.Create(options => - { - options.UseAutofac(); - })) - { - application.Initialize(); + application.Initialize(); - Console.WriteLine("Started: " + typeof(Program).Namespace); - Console.WriteLine("Press ENTER to stop the application..!"); - Console.ReadLine(); + Console.WriteLine("Started: " + typeof(Program).Namespace); + Console.WriteLine("Press ENTER to stop the application..!"); + Console.ReadLine(); - application.Shutdown(); - } + application.Shutdown(); } } } diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz/DemoAppQuartzModule.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz/DemoAppQuartzModule.cs index d5aa618952..0d521baf3d 100644 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz/DemoAppQuartzModule.cs +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz/DemoAppQuartzModule.cs @@ -3,15 +3,14 @@ using Volo.Abp.BackgroundJobs.DemoApp.Shared; using Volo.Abp.BackgroundJobs.Quartz; using Volo.Abp.Modularity; -namespace Volo.Abp.BackgroundJobs.DemoApp.Quartz +namespace Volo.Abp.BackgroundJobs.DemoApp.Quartz; + +[DependsOn( + typeof(DemoAppSharedModule), + typeof(AbpAutofacModule), + typeof(AbpBackgroundJobsQuartzModule) +)] +public class DemoAppQuartzModule : AbpModule { - [DependsOn( - typeof(DemoAppSharedModule), - typeof(AbpAutofacModule), - typeof(AbpBackgroundJobsQuartzModule) - )] - public class DemoAppQuartzModule : AbpModule - { - } } diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz/Program.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz/Program.cs index 9efe5e4350..1ececcd621 100644 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz/Program.cs +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz/Program.cs @@ -1,24 +1,23 @@ using System; -namespace Volo.Abp.BackgroundJobs.DemoApp.Quartz +namespace Volo.Abp.BackgroundJobs.DemoApp.Quartz; + +class Program { - class Program + static void Main(string[] args) { - static void Main(string[] args) + using (var application = AbpApplicationFactory.Create(options => + { + options.UseAutofac(); + })) { - using (var application = AbpApplicationFactory.Create(options => - { - options.UseAutofac(); - })) - { - application.Initialize(); + application.Initialize(); - Console.WriteLine("Started: " + typeof(Program).Namespace); - Console.WriteLine("Press ENTER to stop the application..!"); - Console.ReadLine(); + Console.WriteLine("Started: " + typeof(Program).Namespace); + Console.WriteLine("Press ENTER to stop the application..!"); + Console.ReadLine(); - application.Shutdown(); - } + application.Shutdown(); } } } diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.RabbitMq/DemoAppRabbitMqModule.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.RabbitMq/DemoAppRabbitMqModule.cs index 8c2e09d37e..952d99da45 100644 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.RabbitMq/DemoAppRabbitMqModule.cs +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.RabbitMq/DemoAppRabbitMqModule.cs @@ -3,15 +3,14 @@ using Volo.Abp.BackgroundJobs.DemoApp.Shared; using Volo.Abp.BackgroundJobs.RabbitMQ; using Volo.Abp.Modularity; -namespace Volo.Abp.BackgroundJobs.DemoApp.RabbitMq +namespace Volo.Abp.BackgroundJobs.DemoApp.RabbitMq; + +[DependsOn( + typeof(DemoAppSharedModule), + typeof(AbpAutofacModule), + typeof(AbpBackgroundJobsRabbitMqModule) +)] +public class DemoAppRabbitMqModule : AbpModule { - [DependsOn( - typeof(DemoAppSharedModule), - typeof(AbpAutofacModule), - typeof(AbpBackgroundJobsRabbitMqModule) - )] - public class DemoAppRabbitMqModule : AbpModule - { - } } diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.RabbitMq/Program.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.RabbitMq/Program.cs index d467006531..5d04169c15 100644 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.RabbitMq/Program.cs +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.RabbitMq/Program.cs @@ -1,24 +1,23 @@ using System; -namespace Volo.Abp.BackgroundJobs.DemoApp.RabbitMq +namespace Volo.Abp.BackgroundJobs.DemoApp.RabbitMq; + +class Program { - class Program + static void Main(string[] args) { - static void Main(string[] args) + using (var application = AbpApplicationFactory.Create(options => + { + options.UseAutofac(); + })) { - using (var application = AbpApplicationFactory.Create(options => - { - options.UseAutofac(); - })) - { - application.Initialize(); + application.Initialize(); - Console.WriteLine("Started: " + typeof(Program).Namespace); - Console.WriteLine("Press ENTER to stop the application..!"); - Console.ReadLine(); + Console.WriteLine("Started: " + typeof(Program).Namespace); + Console.WriteLine("Press ENTER to stop the application..!"); + Console.ReadLine(); - application.Shutdown(); - } + application.Shutdown(); } } } diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Db/DemoAppDbContext.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Db/DemoAppDbContext.cs index 524c741dd7..d34583d540 100644 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Db/DemoAppDbContext.cs +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Db/DemoAppDbContext.cs @@ -2,21 +2,20 @@ using Volo.Abp.BackgroundJobs.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; -namespace Volo.Abp.BackgroundJobs.DemoApp.Db +namespace Volo.Abp.BackgroundJobs.DemoApp.Db; + +public class DemoAppDbContext : AbpDbContext { - public class DemoAppDbContext : AbpDbContext + public DemoAppDbContext(DbContextOptions options) + : base(options) { - public DemoAppDbContext(DbContextOptions options) - : base(options) - { - } + } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); - modelBuilder.ConfigureBackgroundJobs(); - } + modelBuilder.ConfigureBackgroundJobs(); } } diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Db/DemoAppDbContextFactory.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Db/DemoAppDbContextFactory.cs index 95e9a7874a..b71eca7bec 100644 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Db/DemoAppDbContextFactory.cs +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Db/DemoAppDbContextFactory.cs @@ -3,27 +3,26 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; using Microsoft.Extensions.Configuration; -namespace Volo.Abp.BackgroundJobs.DemoApp.Db +namespace Volo.Abp.BackgroundJobs.DemoApp.Db; + +public class DemoAppDbContextFactory : IDesignTimeDbContextFactory { - public class DemoAppDbContextFactory : IDesignTimeDbContextFactory + public DemoAppDbContext CreateDbContext(string[] args) { - public DemoAppDbContext CreateDbContext(string[] args) - { - var configuration = BuildConfiguration(); + var configuration = BuildConfiguration(); - var builder = new DbContextOptionsBuilder() - .UseSqlServer(configuration.GetConnectionString("Default")); + var builder = new DbContextOptionsBuilder() + .UseSqlServer(configuration.GetConnectionString("Default")); - return new DemoAppDbContext(builder.Options); - } + return new DemoAppDbContext(builder.Options); + } - private static IConfigurationRoot BuildConfiguration() - { - var builder = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json", optional: false); + private static IConfigurationRoot BuildConfiguration() + { + var builder = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json", optional: false); - return builder.Build(); - } + return builder.Build(); } } diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/DemoAppModule.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/DemoAppModule.cs index 589892c901..a909fb476e 100644 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/DemoAppModule.cs +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/DemoAppModule.cs @@ -5,42 +5,41 @@ using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.SqlServer; using Volo.Abp.Modularity; -namespace Volo.Abp.BackgroundJobs.DemoApp +namespace Volo.Abp.BackgroundJobs.DemoApp; + +[DependsOn( + typeof(DemoAppSharedModule), + typeof(AbpBackgroundJobsEntityFrameworkCoreModule), + typeof(AbpAutofacModule), + typeof(AbpEntityFrameworkCoreSqlServerModule) + )] +public class DemoAppModule : AbpModule { - [DependsOn( - typeof(DemoAppSharedModule), - typeof(AbpBackgroundJobsEntityFrameworkCoreModule), - typeof(AbpAutofacModule), - typeof(AbpEntityFrameworkCoreSqlServerModule) - )] - public class DemoAppModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) + Configure(options => { - Configure(options => + options.Configure(opts => { - options.Configure(opts => - { - opts.UseSqlServer(); - }); + opts.UseSqlServer(); }); + }); - Configure(options => - { + Configure(options => + { //Configure for fast running options.JobPollPeriod = 1000; - options.DefaultFirstWaitDuration = 1; - options.DefaultWaitFactor = 1; - }); - } + options.DefaultFirstWaitDuration = 1; + options.DefaultWaitFactor = 1; + }); + } - public override void OnApplicationInitialization(ApplicationInitializationContext context) - { - //TODO: Configure console logging - //context - // .ServiceProvider - // .GetRequiredService() - // .AddConsole(LogLevel.Debug); - } + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + //TODO: Configure console logging + //context + // .ServiceProvider + // .GetRequiredService() + // .AddConsole(LogLevel.Debug); } } diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20201013055401_Initial.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20201013055401_Initial.cs index 99c4a11d89..aa50d3f32a 100644 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20201013055401_Initial.cs +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20201013055401_Initial.cs @@ -1,43 +1,41 @@ using System; using Microsoft.EntityFrameworkCore.Migrations; -namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations +namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations; + +public partial class Initial : Migration { - public partial class Initial : Migration + protected override void Up(MigrationBuilder migrationBuilder) { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "AbpBackgroundJobs", - columns: table => new - { - Id = table.Column(nullable: false), - ExtraProperties = table.Column(nullable: true), - ConcurrencyStamp = table.Column(maxLength: 40, nullable: true), - JobName = table.Column(maxLength: 128, nullable: false), - JobArgs = table.Column(maxLength: 1048576, nullable: false), - TryCount = table.Column(nullable: false, defaultValue: (short)0), - CreationTime = table.Column(nullable: false), - NextTryTime = table.Column(nullable: false), - LastTryTime = table.Column(nullable: true), - IsAbandoned = table.Column(nullable: false, defaultValue: false), - Priority = table.Column(nullable: false, defaultValue: (byte)15) - }, - constraints: table => - { - table.PrimaryKey("PK_AbpBackgroundJobs", x => x.Id); - }); + migrationBuilder.CreateTable( + name: "AbpBackgroundJobs", + columns: table => new { + Id = table.Column(nullable: false), + ExtraProperties = table.Column(nullable: true), + ConcurrencyStamp = table.Column(maxLength: 40, nullable: true), + JobName = table.Column(maxLength: 128, nullable: false), + JobArgs = table.Column(maxLength: 1048576, nullable: false), + TryCount = table.Column(nullable: false, defaultValue: (short)0), + CreationTime = table.Column(nullable: false), + NextTryTime = table.Column(nullable: false), + LastTryTime = table.Column(nullable: true), + IsAbandoned = table.Column(nullable: false, defaultValue: false), + Priority = table.Column(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" }); - } + migrationBuilder.CreateIndex( + name: "IX_AbpBackgroundJobs_IsAbandoned_NextTryTime", + table: "AbpBackgroundJobs", + columns: new[] { "IsAbandoned", "NextTryTime" }); + } - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "AbpBackgroundJobs"); - } + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AbpBackgroundJobs"); } } diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Program.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Program.cs index b8bb19383e..f895e7adbb 100644 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Program.cs +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Program.cs @@ -1,24 +1,23 @@ using System; -namespace Volo.Abp.BackgroundJobs.DemoApp +namespace Volo.Abp.BackgroundJobs.DemoApp; + +class Program { - class Program + static void Main(string[] args) { - static void Main(string[] args) + using (var application = AbpApplicationFactory.Create(options => + { + options.UseAutofac(); + })) { - using (var application = AbpApplicationFactory.Create(options => - { - options.UseAutofac(); - })) - { - application.Initialize(); + application.Initialize(); - Console.WriteLine("Started: " + typeof(Program).Namespace); - Console.WriteLine("Press ENTER to stop the application..!"); - Console.ReadLine(); + Console.WriteLine("Started: " + typeof(Program).Namespace); + Console.WriteLine("Press ENTER to stop the application..!"); + Console.ReadLine(); - application.Shutdown(); - } + application.Shutdown(); } } } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain.Shared/Volo/Abp/BackgroundJobs/AbpBackgroundJobsDomainSharedModule.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain.Shared/Volo/Abp/BackgroundJobs/AbpBackgroundJobsDomainSharedModule.cs index 26565fde78..552f3f497c 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain.Shared/Volo/Abp/BackgroundJobs/AbpBackgroundJobsDomainSharedModule.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain.Shared/Volo/Abp/BackgroundJobs/AbpBackgroundJobsDomainSharedModule.cs @@ -1,9 +1,8 @@ using Volo.Abp.Modularity; -namespace Volo.Abp.BackgroundJobs +namespace Volo.Abp.BackgroundJobs; + +public class AbpBackgroundJobsDomainSharedModule : AbpModule { - public class AbpBackgroundJobsDomainSharedModule : AbpModule - { - - } + } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain.Shared/Volo/Abp/BackgroundJobs/BackgroundJobRecordConsts.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain.Shared/Volo/Abp/BackgroundJobs/BackgroundJobRecordConsts.cs index 01f935b30e..4369bfcece 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain.Shared/Volo/Abp/BackgroundJobs/BackgroundJobRecordConsts.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain.Shared/Volo/Abp/BackgroundJobs/BackgroundJobRecordConsts.cs @@ -1,15 +1,14 @@ -namespace Volo.Abp.BackgroundJobs +namespace Volo.Abp.BackgroundJobs; + +public static class BackgroundJobRecordConsts { - public static class BackgroundJobRecordConsts - { - /// - /// Default value: 128 - /// - public static int MaxJobNameLength { get; set; } = 128; + /// + /// Default value: 128 + /// + public static int MaxJobNameLength { get; set; } = 128; - /// - /// Default value: 1024 * 1024 - /// - public static int MaxJobArgsLength { get; set; } = 1024 * 1024; - } + /// + /// Default value: 1024 * 1024 + /// + public static int MaxJobArgsLength { get; set; } = 1024 * 1024; } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/AbpBackgroundJobsDomainModule.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/AbpBackgroundJobsDomainModule.cs index a373fd883b..1a551ef7c4 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/AbpBackgroundJobsDomainModule.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/AbpBackgroundJobsDomainModule.cs @@ -2,22 +2,21 @@ using Volo.Abp.AutoMapper; using Volo.Abp.Modularity; -namespace Volo.Abp.BackgroundJobs +namespace Volo.Abp.BackgroundJobs; + +[DependsOn( + typeof(AbpBackgroundJobsDomainSharedModule), + typeof(AbpBackgroundJobsModule), + typeof(AbpAutoMapperModule) + )] +public class AbpBackgroundJobsDomainModule : AbpModule { - [DependsOn( - typeof(AbpBackgroundJobsDomainSharedModule), - typeof(AbpBackgroundJobsModule), - typeof(AbpAutoMapperModule) - )] - public class AbpBackgroundJobsDomainModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) + context.Services.AddAutoMapperObjectMapper(); + Configure(options => { - context.Services.AddAutoMapperObjectMapper(); - Configure(options => - { - options.AddProfile(validate: true); - }); - } + options.AddProfile(validate: true); + }); } } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobRecord.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobRecord.cs index c539ea8d89..66714af6d6 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobRecord.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobRecord.cs @@ -2,61 +2,60 @@ using Volo.Abp.Auditing; using Volo.Abp.Domain.Entities; -namespace Volo.Abp.BackgroundJobs +namespace Volo.Abp.BackgroundJobs; + +public class BackgroundJobRecord : AggregateRoot, IHasCreationTime { - public class BackgroundJobRecord : AggregateRoot, IHasCreationTime + /// + /// Type of the job. + /// It's AssemblyQualifiedName of job type. + /// + public virtual string JobName { get; set; } + + /// + /// Job arguments as serialized string. + /// + public virtual string JobArgs { get; set; } + + /// + /// Try count of this job. + /// A job is re-tried if it fails. + /// + public virtual short TryCount { get; set; } + + /// + /// Creation time of this job. + /// + public virtual DateTime CreationTime { get; set; } + + /// + /// Next try time of this job. + /// + public virtual DateTime NextTryTime { get; set; } + + /// + /// Last try time of this job. + /// + public virtual DateTime? LastTryTime { get; set; } + + /// + /// This is true if this job is continuously failed and will not be executed again. + /// + public virtual bool IsAbandoned { get; set; } + + /// + /// Priority of this job. + /// + public virtual BackgroundJobPriority Priority { get; set; } + + protected BackgroundJobRecord() + { + + } + + public BackgroundJobRecord(Guid id) + : base(id) { - /// - /// Type of the job. - /// It's AssemblyQualifiedName of job type. - /// - public virtual string JobName { get; set; } - - /// - /// Job arguments as serialized string. - /// - public virtual string JobArgs { get; set; } - - /// - /// Try count of this job. - /// A job is re-tried if it fails. - /// - public virtual short TryCount { get; set; } - - /// - /// Creation time of this job. - /// - public virtual DateTime CreationTime { get; set; } - - /// - /// Next try time of this job. - /// - public virtual DateTime NextTryTime { get; set; } - - /// - /// Last try time of this job. - /// - public virtual DateTime? LastTryTime { get; set; } - - /// - /// This is true if this job is continuously failed and will not be executed again. - /// - public virtual bool IsAbandoned { get; set; } - - /// - /// Priority of this job. - /// - public virtual BackgroundJobPriority Priority { get; set; } - - protected BackgroundJobRecord() - { - - } - - public BackgroundJobRecord(Guid id) - : base(id) - { - - } + } } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobStore.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobStore.cs index b8d30b6940..e29948cc95 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobStore.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobStore.cs @@ -4,58 +4,57 @@ using System.Threading.Tasks; using Volo.Abp.DependencyInjection; using Volo.Abp.ObjectMapping; -namespace Volo.Abp.BackgroundJobs +namespace Volo.Abp.BackgroundJobs; + +public class BackgroundJobStore : IBackgroundJobStore, ITransientDependency { - public class BackgroundJobStore : IBackgroundJobStore, ITransientDependency - { - protected IBackgroundJobRepository BackgroundJobRepository { get; } + protected IBackgroundJobRepository BackgroundJobRepository { get; } - protected IObjectMapper ObjectMapper { get; } + protected IObjectMapper ObjectMapper { get; } - public BackgroundJobStore( - IBackgroundJobRepository backgroundJobRepository, - IObjectMapper objectMapper) - { - ObjectMapper = objectMapper; - BackgroundJobRepository = backgroundJobRepository; - } + public BackgroundJobStore( + IBackgroundJobRepository backgroundJobRepository, + IObjectMapper objectMapper) + { + ObjectMapper = objectMapper; + BackgroundJobRepository = backgroundJobRepository; + } - public virtual async Task FindAsync(Guid jobId) - { - return ObjectMapper.Map( - await BackgroundJobRepository.FindAsync(jobId) - ); - } + public virtual async Task FindAsync(Guid jobId) + { + return ObjectMapper.Map( + await BackgroundJobRepository.FindAsync(jobId) + ); + } - public virtual async Task InsertAsync(BackgroundJobInfo jobInfo) - { - await BackgroundJobRepository.InsertAsync( - ObjectMapper.Map(jobInfo) - ); - } + public virtual async Task InsertAsync(BackgroundJobInfo jobInfo) + { + await BackgroundJobRepository.InsertAsync( + ObjectMapper.Map(jobInfo) + ); + } - public virtual async Task> GetWaitingJobsAsync(int maxResultCount) - { - return ObjectMapper.Map, List>( - await BackgroundJobRepository.GetWaitingListAsync(maxResultCount) - ); - } + public virtual async Task> GetWaitingJobsAsync(int maxResultCount) + { + return ObjectMapper.Map, List>( + await BackgroundJobRepository.GetWaitingListAsync(maxResultCount) + ); + } - public virtual async Task DeleteAsync(Guid jobId) - { - await BackgroundJobRepository.DeleteAsync(jobId); - } + public virtual async Task DeleteAsync(Guid jobId) + { + await BackgroundJobRepository.DeleteAsync(jobId); + } - public virtual async Task UpdateAsync(BackgroundJobInfo jobInfo) + public virtual async Task UpdateAsync(BackgroundJobInfo jobInfo) + { + var backgroundJobRecord = await BackgroundJobRepository.FindAsync(jobInfo.Id); + if (backgroundJobRecord == null) { - var backgroundJobRecord = await BackgroundJobRepository.FindAsync(jobInfo.Id); - if (backgroundJobRecord == null) - { - return; - } - - ObjectMapper.Map(jobInfo, backgroundJobRecord); - await BackgroundJobRepository.UpdateAsync(backgroundJobRecord); + return; } + + ObjectMapper.Map(jobInfo, backgroundJobRecord); + await BackgroundJobRepository.UpdateAsync(backgroundJobRecord); } } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobsDbProperties.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobsDbProperties.cs index 6ef52d5037..401aa379a7 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobsDbProperties.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobsDbProperties.cs @@ -1,13 +1,12 @@ using Volo.Abp.Data; -namespace Volo.Abp.BackgroundJobs +namespace Volo.Abp.BackgroundJobs; + +public static class BackgroundJobsDbProperties { - public static class BackgroundJobsDbProperties - { - public static string DbTablePrefix { get; set; } = AbpCommonDbProperties.DbTablePrefix; + public static string DbTablePrefix { get; set; } = AbpCommonDbProperties.DbTablePrefix; - public static string DbSchema { get; set; } = AbpCommonDbProperties.DbSchema; + public static string DbSchema { get; set; } = AbpCommonDbProperties.DbSchema; - public const string ConnectionStringName = "AbpBackgroundJobs"; - } + public const string ConnectionStringName = "AbpBackgroundJobs"; } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobsDomainAutoMapperProfile.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobsDomainAutoMapperProfile.cs index ebf98bbe70..67891f4f91 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobsDomainAutoMapperProfile.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobsDomainAutoMapperProfile.cs @@ -1,18 +1,17 @@ using AutoMapper; using Volo.Abp.AutoMapper; -namespace Volo.Abp.BackgroundJobs +namespace Volo.Abp.BackgroundJobs; + +public class BackgroundJobsDomainAutoMapperProfile : Profile { - public class BackgroundJobsDomainAutoMapperProfile : Profile + public BackgroundJobsDomainAutoMapperProfile() { - public BackgroundJobsDomainAutoMapperProfile() - { - CreateMap() - .ConstructUsing(x => new BackgroundJobRecord(x.Id)) - .Ignore(record => record.ConcurrencyStamp) - .Ignore(record => record.ExtraProperties); + CreateMap() + .ConstructUsing(x => new BackgroundJobRecord(x.Id)) + .Ignore(record => record.ConcurrencyStamp) + .Ignore(record => record.ExtraProperties); - CreateMap(); - } + CreateMap(); } } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/IBackgroundJobRepository.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/IBackgroundJobRepository.cs index 0fdf15de4b..b3c552c974 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/IBackgroundJobRepository.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/IBackgroundJobRepository.cs @@ -4,10 +4,9 @@ using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; -namespace Volo.Abp.BackgroundJobs +namespace Volo.Abp.BackgroundJobs; + +public interface IBackgroundJobRepository : IBasicRepository { - public interface IBackgroundJobRepository : IBasicRepository - { - Task> GetWaitingListAsync(int maxResultCount, CancellationToken cancellationToken = default); - } + Task> GetWaitingListAsync(int maxResultCount, CancellationToken cancellationToken = default); } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/AbpBackgroundJobsEntityFrameworkCoreModule.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/AbpBackgroundJobsEntityFrameworkCoreModule.cs index 1c4e6278a5..243dfc9882 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/AbpBackgroundJobsEntityFrameworkCoreModule.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/AbpBackgroundJobsEntityFrameworkCoreModule.cs @@ -2,20 +2,19 @@ using Volo.Abp.EntityFrameworkCore; using Volo.Abp.Modularity; -namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore +namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore; + +[DependsOn( + typeof(AbpBackgroundJobsDomainModule), + typeof(AbpEntityFrameworkCoreModule) +)] +public class AbpBackgroundJobsEntityFrameworkCoreModule : AbpModule { - [DependsOn( - typeof(AbpBackgroundJobsDomainModule), - typeof(AbpEntityFrameworkCoreModule) - )] - public class AbpBackgroundJobsEntityFrameworkCoreModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) + context.Services.AddAbpDbContext(options => { - context.Services.AddAbpDbContext(options => - { - options.AddRepository(); - }); - } + options.AddRepository(); + }); } -} \ No newline at end of file +} diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/BackgroundJobsDbContext.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/BackgroundJobsDbContext.cs index e49fa3fe55..fb01736cfa 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/BackgroundJobsDbContext.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/BackgroundJobsDbContext.cs @@ -3,25 +3,24 @@ using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.MultiTenancy; -namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore +namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore; + +[IgnoreMultiTenancy] +[ConnectionStringName(BackgroundJobsDbProperties.ConnectionStringName)] +public class BackgroundJobsDbContext : AbpDbContext, IBackgroundJobsDbContext { - [IgnoreMultiTenancy] - [ConnectionStringName(BackgroundJobsDbProperties.ConnectionStringName)] - public class BackgroundJobsDbContext : AbpDbContext, IBackgroundJobsDbContext - { - public DbSet BackgroundJobs { get; set; } + public DbSet BackgroundJobs { get; set; } - public BackgroundJobsDbContext(DbContextOptions options) - : base(options) - { + public BackgroundJobsDbContext(DbContextOptions options) + : base(options) + { - } + } - protected override void OnModelCreating(ModelBuilder builder) - { - base.OnModelCreating(builder); + protected override void OnModelCreating(ModelBuilder builder) + { + base.OnModelCreating(builder); - builder.ConfigureBackgroundJobs(); - } + builder.ConfigureBackgroundJobs(); } } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/BackgroundJobsDbContextModelCreatingExtensions.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/BackgroundJobsDbContextModelCreatingExtensions.cs index 1781c7067d..bf9f8d5ea3 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/BackgroundJobsDbContextModelCreatingExtensions.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/BackgroundJobsDbContextModelCreatingExtensions.cs @@ -2,40 +2,39 @@ using Microsoft.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.Modeling; -namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore +namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore; + +public static class BackgroundJobsDbContextModelCreatingExtensions { - public static class BackgroundJobsDbContextModelCreatingExtensions + public static void ConfigureBackgroundJobs( + this ModelBuilder builder) { - public static void ConfigureBackgroundJobs( - this ModelBuilder builder) - { - Check.NotNull(builder, nameof(builder)); + Check.NotNull(builder, nameof(builder)); - if (builder.IsTenantOnlyDatabase()) - { - return; - } + if (builder.IsTenantOnlyDatabase()) + { + return; + } - builder.Entity(b => - { - b.ToTable(BackgroundJobsDbProperties.DbTablePrefix + "BackgroundJobs", BackgroundJobsDbProperties.DbSchema); + builder.Entity(b => + { + b.ToTable(BackgroundJobsDbProperties.DbTablePrefix + "BackgroundJobs", BackgroundJobsDbProperties.DbSchema); - b.ConfigureByConvention(); + b.ConfigureByConvention(); - b.Property(x => x.JobName).IsRequired().HasMaxLength(BackgroundJobRecordConsts.MaxJobNameLength); - b.Property(x => x.JobArgs).IsRequired().HasMaxLength(BackgroundJobRecordConsts.MaxJobArgsLength); - b.Property(x => x.TryCount).HasDefaultValue(0); - b.Property(x => x.NextTryTime); - b.Property(x => x.LastTryTime); - b.Property(x => x.IsAbandoned).HasDefaultValue(false); - b.Property(x => x.Priority).HasDefaultValue(BackgroundJobPriority.Normal); + b.Property(x => x.JobName).IsRequired().HasMaxLength(BackgroundJobRecordConsts.MaxJobNameLength); + b.Property(x => x.JobArgs).IsRequired().HasMaxLength(BackgroundJobRecordConsts.MaxJobArgsLength); + b.Property(x => x.TryCount).HasDefaultValue(0); + b.Property(x => x.NextTryTime); + b.Property(x => x.LastTryTime); + b.Property(x => x.IsAbandoned).HasDefaultValue(false); + b.Property(x => x.Priority).HasDefaultValue(BackgroundJobPriority.Normal); - b.HasIndex(x => new { x.IsAbandoned, x.NextTryTime }); + b.HasIndex(x => new { x.IsAbandoned, x.NextTryTime }); - b.ApplyObjectExtensionMappings(); - }); + b.ApplyObjectExtensionMappings(); + }); - builder.TryConfigureObjectExtensions(); - } + builder.TryConfigureObjectExtensions(); } } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/EfCoreBackgroundJobRepository.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/EfCoreBackgroundJobRepository.cs index 3ae5d2a409..a2be3c6e1e 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/EfCoreBackgroundJobRepository.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/EfCoreBackgroundJobRepository.cs @@ -8,36 +8,35 @@ using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.Timing; -namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore +namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore; + +public class EfCoreBackgroundJobRepository : EfCoreRepository, IBackgroundJobRepository { - public class EfCoreBackgroundJobRepository : EfCoreRepository, IBackgroundJobRepository - { - protected IClock Clock { get; } + protected IClock Clock { get; } - public EfCoreBackgroundJobRepository( - IDbContextProvider dbContextProvider, - IClock clock) - : base(dbContextProvider) - { - Clock = clock; - } + public EfCoreBackgroundJobRepository( + IDbContextProvider dbContextProvider, + IClock clock) + : base(dbContextProvider) + { + Clock = clock; + } - public virtual async Task> GetWaitingListAsync( - int maxResultCount, - CancellationToken cancellationToken = default) - { - return await (await GetWaitingListQueryAsync(maxResultCount)).ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task> GetWaitingListAsync( + int maxResultCount, + CancellationToken cancellationToken = default) + { + return await (await GetWaitingListQueryAsync(maxResultCount)).ToListAsync(GetCancellationToken(cancellationToken)); + } - protected virtual async Task> GetWaitingListQueryAsync(int maxResultCount) - { - var now = Clock.Now; - return (await GetDbSetAsync()) - .Where(t => !t.IsAbandoned && t.NextTryTime <= now) - .OrderByDescending(t => t.Priority) - .ThenBy(t => t.TryCount) - .ThenBy(t => t.NextTryTime) - .Take(maxResultCount); - } + protected virtual async Task> GetWaitingListQueryAsync(int maxResultCount) + { + var now = Clock.Now; + return (await GetDbSetAsync()) + .Where(t => !t.IsAbandoned && t.NextTryTime <= now) + .OrderByDescending(t => t.Priority) + .ThenBy(t => t.TryCount) + .ThenBy(t => t.NextTryTime) + .Take(maxResultCount); } } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/IBackgroundJobsDbContext.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/IBackgroundJobsDbContext.cs index 46701b863e..b091ac126a 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/IBackgroundJobsDbContext.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/IBackgroundJobsDbContext.cs @@ -3,12 +3,11 @@ using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.MultiTenancy; -namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore +namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore; + +[IgnoreMultiTenancy] +[ConnectionStringName(BackgroundJobsDbProperties.ConnectionStringName)] +public interface IBackgroundJobsDbContext : IEfCoreDbContext { - [IgnoreMultiTenancy] - [ConnectionStringName(BackgroundJobsDbProperties.ConnectionStringName)] - public interface IBackgroundJobsDbContext : IEfCoreDbContext - { - DbSet BackgroundJobs { get; } - } + DbSet BackgroundJobs { get; } } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Installer/Volo/Abp/BackgroundJobs/AbpBackgroundJobsInstallerModule.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Installer/Volo/Abp/BackgroundJobs/AbpBackgroundJobsInstallerModule.cs index fb1bcf4014..1e17c8cfd9 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Installer/Volo/Abp/BackgroundJobs/AbpBackgroundJobsInstallerModule.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Installer/Volo/Abp/BackgroundJobs/AbpBackgroundJobsInstallerModule.cs @@ -2,20 +2,19 @@ using Volo.Abp.Studio; using Volo.Abp.VirtualFileSystem; -namespace Volo.Abp.BackgroundJobs +namespace Volo.Abp.BackgroundJobs; + +[DependsOn( + typeof(AbpStudioModuleInstallerModule), + typeof(AbpVirtualFileSystemModule) + )] +public class AbpBackgroundJobsInstallerModule : AbpModule { - [DependsOn( - typeof(AbpStudioModuleInstallerModule), - typeof(AbpVirtualFileSystemModule) - )] - public class AbpBackgroundJobsInstallerModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) + Configure(options => { - Configure(options => - { - options.FileSets.AddEmbedded(); - }); - } + options.FileSets.AddEmbedded(); + }); } } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Installer/Volo/Abp/BackgroundJobs/BackgroundJobsInstallerPipelineBuilder.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Installer/Volo/Abp/BackgroundJobs/BackgroundJobsInstallerPipelineBuilder.cs index 8011bd2272..ebe2feac61 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Installer/Volo/Abp/BackgroundJobs/BackgroundJobsInstallerPipelineBuilder.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.Installer/Volo/Abp/BackgroundJobs/BackgroundJobsInstallerPipelineBuilder.cs @@ -3,22 +3,21 @@ using Microsoft.Extensions.DependencyInjection; using Volo.Abp.DependencyInjection; using Volo.Abp.Studio.ModuleInstalling; -namespace Volo.Abp.BackgroundJobs +namespace Volo.Abp.BackgroundJobs; + +[Dependency(ServiceLifetime.Transient, ReplaceServices = true)] +[ExposeServices(typeof(IModuleInstallingPipelineBuilder))] +public class BackgroundJobsInstallerPipelineBuilder : ModuleInstallingPipelineBuilderBase, IModuleInstallingPipelineBuilder, ITransientDependency { - [Dependency(ServiceLifetime.Transient, ReplaceServices = true)] - [ExposeServices(typeof(IModuleInstallingPipelineBuilder))] - public class BackgroundJobsInstallerPipelineBuilder : ModuleInstallingPipelineBuilderBase, IModuleInstallingPipelineBuilder, ITransientDependency + public async Task BuildAsync(ModuleInstallingContext context) { - public async Task BuildAsync(ModuleInstallingContext context) - { - context.AddEfCoreConfigurationMethodDeclaration( - new EfCoreConfigurationMethodDeclaration( - "Volo.Abp.BackgroundJobs.EntityFrameworkCore", - "ConfigureBackgroundJobs" - ) - ); - - return GetBasePipeline(context); - } + context.AddEfCoreConfigurationMethodDeclaration( + new EfCoreConfigurationMethodDeclaration( + "Volo.Abp.BackgroundJobs.EntityFrameworkCore", + "ConfigureBackgroundJobs" + ) + ); + + return GetBasePipeline(context); } } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/AbpBackgroundJobsMongoDbModule.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/AbpBackgroundJobsMongoDbModule.cs index 3e98ea6bc2..46baef68ba 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/AbpBackgroundJobsMongoDbModule.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/AbpBackgroundJobsMongoDbModule.cs @@ -2,20 +2,19 @@ using Volo.Abp.Modularity; using Volo.Abp.MongoDB; -namespace Volo.Abp.BackgroundJobs.MongoDB +namespace Volo.Abp.BackgroundJobs.MongoDB; + +[DependsOn( + typeof(AbpBackgroundJobsDomainModule), + typeof(AbpMongoDbModule) + )] +public class AbpBackgroundJobsMongoDbModule : AbpModule { - [DependsOn( - typeof(AbpBackgroundJobsDomainModule), - typeof(AbpMongoDbModule) - )] - public class AbpBackgroundJobsMongoDbModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) + context.Services.AddMongoDbContext(options => { - context.Services.AddMongoDbContext(options => - { - options.AddRepository(); - }); - } + options.AddRepository(); + }); } } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobsMongoDbContext.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobsMongoDbContext.cs index 13a058bc33..42b8a44f0d 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobsMongoDbContext.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobsMongoDbContext.cs @@ -3,19 +3,18 @@ using Volo.Abp.Data; using Volo.Abp.MongoDB; using Volo.Abp.MultiTenancy; -namespace Volo.Abp.BackgroundJobs.MongoDB +namespace Volo.Abp.BackgroundJobs.MongoDB; + +[IgnoreMultiTenancy] +[ConnectionStringName(BackgroundJobsDbProperties.ConnectionStringName)] +public class BackgroundJobsMongoDbContext : AbpMongoDbContext, IBackgroundJobsMongoDbContext { - [IgnoreMultiTenancy] - [ConnectionStringName(BackgroundJobsDbProperties.ConnectionStringName)] - public class BackgroundJobsMongoDbContext : AbpMongoDbContext, IBackgroundJobsMongoDbContext - { - public IMongoCollection BackgroundJobs { get; set; } + public IMongoCollection BackgroundJobs { get; set; } - protected override void CreateModel(IMongoModelBuilder modelBuilder) - { - base.CreateModel(modelBuilder); + protected override void CreateModel(IMongoModelBuilder modelBuilder) + { + base.CreateModel(modelBuilder); - modelBuilder.ConfigureBackgroundJobs(); - } + modelBuilder.ConfigureBackgroundJobs(); } } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobsMongoDbContextExtensions.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobsMongoDbContextExtensions.cs index 410218e5e6..b687bf8f90 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobsMongoDbContextExtensions.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobsMongoDbContextExtensions.cs @@ -1,18 +1,17 @@ using Volo.Abp.MongoDB; -namespace Volo.Abp.BackgroundJobs.MongoDB +namespace Volo.Abp.BackgroundJobs.MongoDB; + +public static class BackgroundJobsMongoDbContextExtensions { - public static class BackgroundJobsMongoDbContextExtensions + public static void ConfigureBackgroundJobs( + this IMongoModelBuilder builder) { - public static void ConfigureBackgroundJobs( - this IMongoModelBuilder builder) - { - Check.NotNull(builder, nameof(builder)); + Check.NotNull(builder, nameof(builder)); - builder.Entity(b => - { - b.CollectionName = BackgroundJobsDbProperties.DbTablePrefix + "BackgroundJobs"; - }); - } + builder.Entity(b => + { + b.CollectionName = BackgroundJobsDbProperties.DbTablePrefix + "BackgroundJobs"; + }); } } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/IBackgroundJobsMongoDbContext.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/IBackgroundJobsMongoDbContext.cs index 254d22d63c..4f93e1cbe5 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/IBackgroundJobsMongoDbContext.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/IBackgroundJobsMongoDbContext.cs @@ -3,12 +3,11 @@ using Volo.Abp.Data; using Volo.Abp.MongoDB; using Volo.Abp.MultiTenancy; -namespace Volo.Abp.BackgroundJobs.MongoDB +namespace Volo.Abp.BackgroundJobs.MongoDB; + +[IgnoreMultiTenancy] +[ConnectionStringName(BackgroundJobsDbProperties.ConnectionStringName)] +public interface IBackgroundJobsMongoDbContext : IAbpMongoDbContext { - [IgnoreMultiTenancy] - [ConnectionStringName(BackgroundJobsDbProperties.ConnectionStringName)] - public interface IBackgroundJobsMongoDbContext : IAbpMongoDbContext - { - IMongoCollection BackgroundJobs { get; } - } + IMongoCollection BackgroundJobs { get; } } diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs index 56d0bfaff1..5993fdf9ba 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs @@ -8,36 +8,35 @@ using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; using Volo.Abp.Timing; -namespace Volo.Abp.BackgroundJobs.MongoDB +namespace Volo.Abp.BackgroundJobs.MongoDB; + +public class MongoBackgroundJobRepository : MongoDbRepository, IBackgroundJobRepository { - public class MongoBackgroundJobRepository : MongoDbRepository, IBackgroundJobRepository - { - protected IClock Clock { get; } + protected IClock Clock { get; } - public MongoBackgroundJobRepository( - IMongoDbContextProvider dbContextProvider, - IClock clock) - : base(dbContextProvider) - { - Clock = clock; - } + public MongoBackgroundJobRepository( + IMongoDbContextProvider dbContextProvider, + IClock clock) + : base(dbContextProvider) + { + Clock = clock; + } - public virtual async Task> GetWaitingListAsync( - int maxResultCount, - CancellationToken cancellationToken = default) - { - return await (await GetWaitingListQuery(maxResultCount)).ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task> GetWaitingListAsync( + int maxResultCount, + CancellationToken cancellationToken = default) + { + return await (await GetWaitingListQuery(maxResultCount)).ToListAsync(GetCancellationToken(cancellationToken)); + } - protected virtual async Task> GetWaitingListQuery(int maxResultCount, CancellationToken cancellationToken = default) - { - var now = Clock.Now; - return (await GetMongoQueryableAsync(cancellationToken)) - .Where(t => !t.IsAbandoned && t.NextTryTime <= now) - .OrderByDescending(t => t.Priority) - .ThenBy(t => t.TryCount) - .ThenBy(t => t.NextTryTime) - .Take(maxResultCount); - } + protected virtual async Task> GetWaitingListQuery(int maxResultCount, CancellationToken cancellationToken = default) + { + var now = Clock.Now; + return (await GetMongoQueryableAsync(cancellationToken)) + .Where(t => !t.IsAbandoned && t.NextTryTime <= now) + .OrderByDescending(t => t.Priority) + .ThenBy(t => t.TryCount) + .ThenBy(t => t.NextTryTime) + .Take(maxResultCount); } } diff --git a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.Domain.Tests/Volo/Abp/BackgroundJobs/AbpBackgroundJobsDomainTestModule.cs b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.Domain.Tests/Volo/Abp/BackgroundJobs/AbpBackgroundJobsDomainTestModule.cs index a9a4bff069..357e7ec20f 100644 --- a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.Domain.Tests/Volo/Abp/BackgroundJobs/AbpBackgroundJobsDomainTestModule.cs +++ b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.Domain.Tests/Volo/Abp/BackgroundJobs/AbpBackgroundJobsDomainTestModule.cs @@ -1,13 +1,12 @@ using Volo.Abp.BackgroundJobs.EntityFrameworkCore; using Volo.Abp.Modularity; -namespace Volo.Abp.BackgroundJobs +namespace Volo.Abp.BackgroundJobs; + +[DependsOn( + typeof(AbpBackgroundJobsEntityFrameworkCoreTestModule) + )] +public class AbpBackgroundJobsDomainTestModule : AbpModule { - [DependsOn( - typeof(AbpBackgroundJobsEntityFrameworkCoreTestModule) - )] - public class AbpBackgroundJobsDomainTestModule : AbpModule - { - - } + } diff --git a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.Domain.Tests/Volo/Abp/BackgroundJobs/BackgroundJobStore_Tests.cs b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.Domain.Tests/Volo/Abp/BackgroundJobs/BackgroundJobStore_Tests.cs index caa9a3c445..0e6929a4d4 100644 --- a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.Domain.Tests/Volo/Abp/BackgroundJobs/BackgroundJobStore_Tests.cs +++ b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.Domain.Tests/Volo/Abp/BackgroundJobs/BackgroundJobStore_Tests.cs @@ -3,36 +3,35 @@ using System.Threading.Tasks; using Shouldly; using Xunit; -namespace Volo.Abp.BackgroundJobs +namespace Volo.Abp.BackgroundJobs; + +public class BackgroundJobStore_Tests : BackgroundJobsDomainTestBase { - public class BackgroundJobStore_Tests : BackgroundJobsDomainTestBase - { - private readonly IBackgroundJobStore _backgroundJobStore; + private readonly IBackgroundJobStore _backgroundJobStore; - public BackgroundJobStore_Tests() - { - _backgroundJobStore = GetRequiredService(); - } + public BackgroundJobStore_Tests() + { + _backgroundJobStore = GetRequiredService(); + } - [Fact] - public async Task InsertAsync() + [Fact] + public async Task InsertAsync() + { + var jobInfo = new BackgroundJobInfo { - var jobInfo = new BackgroundJobInfo - { - Id = Guid.NewGuid(), - JobArgs = "args1", - JobName = "name1" - }; + Id = Guid.NewGuid(), + JobArgs = "args1", + JobName = "name1" + }; - await _backgroundJobStore.InsertAsync( - jobInfo - ); + await _backgroundJobStore.InsertAsync( + jobInfo + ); - var jobInfo2 = await _backgroundJobStore.FindAsync(jobInfo.Id); - jobInfo2.ShouldNotBeNull(); - jobInfo2.Id.ShouldBe(jobInfo.Id); - jobInfo2.JobArgs.ShouldBe(jobInfo.JobArgs); - jobInfo2.JobName.ShouldBe(jobInfo.JobName); - } + var jobInfo2 = await _backgroundJobStore.FindAsync(jobInfo.Id); + jobInfo2.ShouldNotBeNull(); + jobInfo2.Id.ShouldBe(jobInfo.Id); + jobInfo2.JobArgs.ShouldBe(jobInfo.JobArgs); + jobInfo2.JobName.ShouldBe(jobInfo.JobName); } } diff --git a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.Domain.Tests/Volo/Abp/BackgroundJobs/BackgroundJobsDomainTestBase.cs b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.Domain.Tests/Volo/Abp/BackgroundJobs/BackgroundJobsDomainTestBase.cs index ae1a2064d3..7138c850e6 100644 --- a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.Domain.Tests/Volo/Abp/BackgroundJobs/BackgroundJobsDomainTestBase.cs +++ b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.Domain.Tests/Volo/Abp/BackgroundJobs/BackgroundJobsDomainTestBase.cs @@ -1,7 +1,6 @@ -namespace Volo.Abp.BackgroundJobs +namespace Volo.Abp.BackgroundJobs; + +public abstract class BackgroundJobsDomainTestBase : BackgroundJobsTestBase { - public abstract class BackgroundJobsDomainTestBase : BackgroundJobsTestBase - { - } -} \ No newline at end of file +} diff --git a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.EntityFrameworkCore.Tests/Volo/Abp/BackgroundJobs/EntityFrameworkCore/AbpBackgroundJobsEntityFrameworkCoreTestModule.cs b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.EntityFrameworkCore.Tests/Volo/Abp/BackgroundJobs/EntityFrameworkCore/AbpBackgroundJobsEntityFrameworkCoreTestModule.cs index 042bbf00a3..a642ddc227 100644 --- a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.EntityFrameworkCore.Tests/Volo/Abp/BackgroundJobs/EntityFrameworkCore/AbpBackgroundJobsEntityFrameworkCoreTestModule.cs +++ b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.EntityFrameworkCore.Tests/Volo/Abp/BackgroundJobs/EntityFrameworkCore/AbpBackgroundJobsEntityFrameworkCoreTestModule.cs @@ -7,38 +7,37 @@ using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.Sqlite; using Volo.Abp.Modularity; -namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore +namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore; + +[DependsOn( + typeof(AbpBackgroundJobsTestBaseModule), + typeof(AbpBackgroundJobsEntityFrameworkCoreModule), + typeof(AbpEntityFrameworkCoreSqliteModule) + )] +public class AbpBackgroundJobsEntityFrameworkCoreTestModule : AbpModule { - [DependsOn( - typeof(AbpBackgroundJobsTestBaseModule), - typeof(AbpBackgroundJobsEntityFrameworkCoreModule), - typeof(AbpEntityFrameworkCoreSqliteModule) - )] - public class AbpBackgroundJobsEntityFrameworkCoreTestModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) - { - var sqliteConnection = CreateDatabaseAndGetConnection(); + var sqliteConnection = CreateDatabaseAndGetConnection(); - Configure(options => + Configure(options => + { + options.Configure(abpDbContextConfigurationContext => { - options.Configure(abpDbContextConfigurationContext => - { - abpDbContextConfigurationContext.DbContextOptions.UseSqlite(sqliteConnection); - }); + abpDbContextConfigurationContext.DbContextOptions.UseSqlite(sqliteConnection); }); - } - - private static SqliteConnection CreateDatabaseAndGetConnection() - { - var connection = new SqliteConnection("Data Source=:memory:"); - connection.Open(); + }); + } + + private static SqliteConnection CreateDatabaseAndGetConnection() + { + var connection = new SqliteConnection("Data Source=:memory:"); + connection.Open(); + + new BackgroundJobsDbContext( + new DbContextOptionsBuilder().UseSqlite(connection).Options + ).GetService().CreateTables(); - new BackgroundJobsDbContext( - new DbContextOptionsBuilder().UseSqlite(connection).Options - ).GetService().CreateTables(); - - return connection; - } + return connection; } } diff --git a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.EntityFrameworkCore.Tests/Volo/Abp/BackgroundJobs/EntityFrameworkCore/BackgroundJobRepositoryTests.cs b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.EntityFrameworkCore.Tests/Volo/Abp/BackgroundJobs/EntityFrameworkCore/BackgroundJobRepositoryTests.cs index 42c412037e..3cff35a71e 100644 --- a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.EntityFrameworkCore.Tests/Volo/Abp/BackgroundJobs/EntityFrameworkCore/BackgroundJobRepositoryTests.cs +++ b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.EntityFrameworkCore.Tests/Volo/Abp/BackgroundJobs/EntityFrameworkCore/BackgroundJobRepositoryTests.cs @@ -1,7 +1,6 @@ -namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore +namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore; + +public class BackgroundJobRepositoryTests : BackgroundJobRepository_Tests { - public class BackgroundJobRepositoryTests : BackgroundJobRepository_Tests - { - } } diff --git a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/AbpBackgroundJobsMongoDbTestModule.cs b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/AbpBackgroundJobsMongoDbTestModule.cs index d1dcaa2a2e..77a6dc6321 100644 --- a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/AbpBackgroundJobsMongoDbTestModule.cs +++ b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/AbpBackgroundJobsMongoDbTestModule.cs @@ -3,25 +3,24 @@ using Volo.Abp.Data; using Volo.Abp.Modularity; using Volo.Abp.Uow; -namespace Volo.Abp.BackgroundJobs.MongoDB +namespace Volo.Abp.BackgroundJobs.MongoDB; + +[DependsOn( + typeof(AbpBackgroundJobsTestBaseModule), + typeof(AbpBackgroundJobsMongoDbModule) + )] +public class AbpBackgroundJobsMongoDbTestModule : AbpModule { - [DependsOn( - typeof(AbpBackgroundJobsTestBaseModule), - typeof(AbpBackgroundJobsMongoDbModule) - )] - public class AbpBackgroundJobsMongoDbTestModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) - { - var stringArray = MongoDbFixture.ConnectionString.Split('?'); - var connectionString = stringArray[0].EnsureEndsWith('/') + - "Db_" + - Guid.NewGuid().ToString("N") + "/?" + stringArray[1]; + var stringArray = MongoDbFixture.ConnectionString.Split('?'); + var connectionString = stringArray[0].EnsureEndsWith('/') + + "Db_" + + Guid.NewGuid().ToString("N") + "/?" + stringArray[1]; - Configure(options => - { - options.ConnectionStrings.Default = connectionString; - }); - } + Configure(options => + { + options.ConnectionStrings.Default = connectionString; + }); } } diff --git a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobRepositoryTests.cs b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobRepositoryTests.cs index f3827c50e2..cff24ce67a 100644 --- a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobRepositoryTests.cs +++ b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobRepositoryTests.cs @@ -1,10 +1,9 @@ using Xunit; -namespace Volo.Abp.BackgroundJobs.MongoDB +namespace Volo.Abp.BackgroundJobs.MongoDB; + +[Collection((MongoTestCollection.Name))] +public class BackgroundJobRepositoryTests : BackgroundJobRepository_Tests { - [Collection((MongoTestCollection.Name))] - public class BackgroundJobRepositoryTests : BackgroundJobRepository_Tests - { - } } diff --git a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/MongoDbFixture.cs b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/MongoDbFixture.cs index a348587184..45a4e14bc7 100644 --- a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/MongoDbFixture.cs +++ b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/MongoDbFixture.cs @@ -1,22 +1,21 @@ using System; using Mongo2Go; -namespace Volo.Abp.BackgroundJobs.MongoDB +namespace Volo.Abp.BackgroundJobs.MongoDB; + +public class MongoDbFixture : IDisposable { - public class MongoDbFixture : IDisposable - { - private static readonly MongoDbRunner MongoDbRunner; - public static readonly string ConnectionString; + private static readonly MongoDbRunner MongoDbRunner; + public static readonly string ConnectionString; - static MongoDbFixture() - { - MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 20); - ConnectionString = MongoDbRunner.ConnectionString; - } + static MongoDbFixture() + { + MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 20); + ConnectionString = MongoDbRunner.ConnectionString; + } - public void Dispose() - { - MongoDbRunner?.Dispose(); - } + public void Dispose() + { + MongoDbRunner?.Dispose(); } } diff --git a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/MongoTestCollection.cs b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/MongoTestCollection.cs index 0096ae6f10..4d10b93788 100644 --- a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/MongoTestCollection.cs +++ b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/MongoTestCollection.cs @@ -1,10 +1,9 @@ using Xunit; -namespace Volo.Abp.BackgroundJobs.MongoDB +namespace Volo.Abp.BackgroundJobs.MongoDB; + +[CollectionDefinition(Name)] +public class MongoTestCollection : ICollectionFixture { - [CollectionDefinition(Name)] - public class MongoTestCollection : ICollectionFixture - { - public const string Name = "MongoDB Collection"; - } -} \ No newline at end of file + public const string Name = "MongoDB Collection"; +} diff --git a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/AbpBackgroundJobsTestBaseModule.cs b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/AbpBackgroundJobsTestBaseModule.cs index 75e150dc25..334e33fbf1 100644 --- a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/AbpBackgroundJobsTestBaseModule.cs +++ b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/AbpBackgroundJobsTestBaseModule.cs @@ -3,36 +3,35 @@ using Volo.Abp.Autofac; using Volo.Abp.Modularity; using Volo.Abp.Threading; -namespace Volo.Abp.BackgroundJobs +namespace Volo.Abp.BackgroundJobs; + +[DependsOn( + typeof(AbpAutofacModule), + typeof(AbpTestBaseModule), + typeof(AbpBackgroundJobsDomainModule) + )] +public class AbpBackgroundJobsTestBaseModule : AbpModule { - [DependsOn( - typeof(AbpAutofacModule), - typeof(AbpTestBaseModule), - typeof(AbpBackgroundJobsDomainModule) - )] - public class AbpBackgroundJobsTestBaseModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) + Configure(options => { - Configure(options => - { - options.IsJobExecutionEnabled = false; - }); - } + options.IsJobExecutionEnabled = false; + }); + } - public override void OnApplicationInitialization(ApplicationInitializationContext context) - { - SeedTestData(context); - } + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + SeedTestData(context); + } - private static void SeedTestData(ApplicationInitializationContext context) + private static void SeedTestData(ApplicationInitializationContext context) + { + using (var scope = context.ServiceProvider.CreateScope()) { - using (var scope = context.ServiceProvider.CreateScope()) - { - AsyncHelper.RunSync(() => scope.ServiceProvider - .GetRequiredService() - .BuildAsync()); - } + AsyncHelper.RunSync(() => scope.ServiceProvider + .GetRequiredService() + .BuildAsync()); } } } diff --git a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobRepository_Tests.cs b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobRepository_Tests.cs index 59a2709edd..02e4fa9d60 100644 --- a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobRepository_Tests.cs +++ b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobRepository_Tests.cs @@ -4,32 +4,31 @@ using Volo.Abp.Modularity; using Volo.Abp.Timing; using Xunit; -namespace Volo.Abp.BackgroundJobs +namespace Volo.Abp.BackgroundJobs; + +public abstract class BackgroundJobRepository_Tests : BackgroundJobsTestBase + where TStartupModule : IAbpModule { - public abstract class BackgroundJobRepository_Tests : BackgroundJobsTestBase - where TStartupModule : IAbpModule - { - private readonly IBackgroundJobRepository _backgroundJobRepository; - private readonly IClock _clock; + private readonly IBackgroundJobRepository _backgroundJobRepository; + private readonly IClock _clock; - protected BackgroundJobRepository_Tests() - { - _backgroundJobRepository = GetRequiredService(); - _clock = GetRequiredService(); - } + protected BackgroundJobRepository_Tests() + { + _backgroundJobRepository = GetRequiredService(); + _clock = GetRequiredService(); + } - [Theory] - [InlineData(2)] - [InlineData(5)] - public async Task GetWaitingListAsync(int maxResultCount) - { - var backgroundJobs = await _backgroundJobRepository.GetWaitingListAsync(maxResultCount); + [Theory] + [InlineData(2)] + [InlineData(5)] + public async Task GetWaitingListAsync(int maxResultCount) + { + var backgroundJobs = await _backgroundJobRepository.GetWaitingListAsync(maxResultCount); - backgroundJobs.Count.ShouldBeGreaterThan(0); - backgroundJobs.Count.ShouldBeLessThanOrEqualTo(maxResultCount); + backgroundJobs.Count.ShouldBeGreaterThan(0); + backgroundJobs.Count.ShouldBeLessThanOrEqualTo(maxResultCount); - backgroundJobs.ForEach(j => j.IsAbandoned.ShouldBeFalse()); - backgroundJobs.ForEach(j => j.NextTryTime.ShouldBeLessThanOrEqualTo(_clock.Now.AddSeconds(1))); //1 second tolerance - } + backgroundJobs.ForEach(j => j.IsAbandoned.ShouldBeFalse()); + backgroundJobs.ForEach(j => j.NextTryTime.ShouldBeLessThanOrEqualTo(_clock.Now.AddSeconds(1))); //1 second tolerance } } diff --git a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobsTestBase.cs b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobsTestBase.cs index c87edcd788..37f0854495 100644 --- a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobsTestBase.cs +++ b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobsTestBase.cs @@ -2,14 +2,13 @@ using Volo.Abp.Modularity; using Volo.Abp.Testing; -namespace Volo.Abp.BackgroundJobs +namespace Volo.Abp.BackgroundJobs; + +public abstract class BackgroundJobsTestBase : AbpIntegratedTest + where TStartupModule : IAbpModule { - public abstract class BackgroundJobsTestBase : AbpIntegratedTest - where TStartupModule : IAbpModule + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) { - protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) - { - options.UseAutofac(); - } + options.UseAutofac(); } } diff --git a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobsTestData.cs b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobsTestData.cs index 25a1891d74..0d8b2bfd29 100644 --- a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobsTestData.cs +++ b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobsTestData.cs @@ -1,12 +1,11 @@ using System; using Volo.Abp.DependencyInjection; -namespace Volo.Abp.BackgroundJobs +namespace Volo.Abp.BackgroundJobs; + +public class BackgroundJobsTestData : ISingletonDependency { - public class BackgroundJobsTestData : ISingletonDependency - { - public Guid JobId1 { get; } = Guid.NewGuid(); - public Guid JobId2 { get; } = Guid.NewGuid(); - public Guid JobId3 { get; } = Guid.NewGuid(); - } + public Guid JobId1 { get; } = Guid.NewGuid(); + public Guid JobId2 { get; } = Guid.NewGuid(); + public Guid JobId3 { get; } = Guid.NewGuid(); } diff --git a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobsTestDataBuilder.cs b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobsTestDataBuilder.cs index 16bcc667f5..079a0ab3ea 100644 --- a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobsTestDataBuilder.cs +++ b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobsTestDataBuilder.cs @@ -3,67 +3,66 @@ using System.Threading.Tasks; using Volo.Abp.DependencyInjection; using Volo.Abp.Timing; -namespace Volo.Abp.BackgroundJobs +namespace Volo.Abp.BackgroundJobs; + +public class BackgroundJobsTestDataBuilder : ITransientDependency { - public class BackgroundJobsTestDataBuilder : ITransientDependency - { - private readonly BackgroundJobsTestData _testData; - private readonly IBackgroundJobRepository _backgroundJobRepository; - private readonly IClock _clock; + private readonly BackgroundJobsTestData _testData; + private readonly IBackgroundJobRepository _backgroundJobRepository; + private readonly IClock _clock; - public BackgroundJobsTestDataBuilder( - BackgroundJobsTestData testData, - IBackgroundJobRepository backgroundJobRepository, - IClock clock) - { - _testData = testData; - _backgroundJobRepository = backgroundJobRepository; - _clock = clock; - } + public BackgroundJobsTestDataBuilder( + BackgroundJobsTestData testData, + IBackgroundJobRepository backgroundJobRepository, + IClock clock) + { + _testData = testData; + _backgroundJobRepository = backgroundJobRepository; + _clock = clock; + } - public async Task BuildAsync() - { - await _backgroundJobRepository.InsertAsync( - new BackgroundJobRecord(_testData.JobId1) - { - JobName = "TestJobName", - JobArgs = "{ value: 1 }", - NextTryTime = _clock.Now.Subtract(TimeSpan.FromMinutes(1)), - Priority = BackgroundJobPriority.Normal, - IsAbandoned = false, - LastTryTime = null, - CreationTime = _clock.Now.Subtract(TimeSpan.FromMinutes(2)), - TryCount = 0 - } - ); + public async Task BuildAsync() + { + await _backgroundJobRepository.InsertAsync( + new BackgroundJobRecord(_testData.JobId1) + { + JobName = "TestJobName", + JobArgs = "{ value: 1 }", + NextTryTime = _clock.Now.Subtract(TimeSpan.FromMinutes(1)), + Priority = BackgroundJobPriority.Normal, + IsAbandoned = false, + LastTryTime = null, + CreationTime = _clock.Now.Subtract(TimeSpan.FromMinutes(2)), + TryCount = 0 + } + ); - await _backgroundJobRepository.InsertAsync( - new BackgroundJobRecord(_testData.JobId2) - { - JobName = "TestJobName", - JobArgs = "{ value: 2 }", - NextTryTime = _clock.Now.AddMinutes(42), - Priority = BackgroundJobPriority.AboveNormal, - IsAbandoned = true, - LastTryTime = _clock.Now.Subtract(TimeSpan.FromDays(1)), - CreationTime = _clock.Now.Subtract(TimeSpan.FromDays(2)), - TryCount = 3 - } - ); + await _backgroundJobRepository.InsertAsync( + new BackgroundJobRecord(_testData.JobId2) + { + JobName = "TestJobName", + JobArgs = "{ value: 2 }", + NextTryTime = _clock.Now.AddMinutes(42), + Priority = BackgroundJobPriority.AboveNormal, + IsAbandoned = true, + LastTryTime = _clock.Now.Subtract(TimeSpan.FromDays(1)), + CreationTime = _clock.Now.Subtract(TimeSpan.FromDays(2)), + TryCount = 3 + } + ); - await _backgroundJobRepository.InsertAsync( - new BackgroundJobRecord(_testData.JobId3) - { - JobName = "TestJobName", - JobArgs = "{ value: 3 }", - NextTryTime = _clock.Now, - Priority = BackgroundJobPriority.BelowNormal, - IsAbandoned = false, - LastTryTime = _clock.Now.Subtract(TimeSpan.FromMinutes(60)), - CreationTime = _clock.Now.Subtract(TimeSpan.FromMinutes(90)), - TryCount = 2 - } - ); - } + await _backgroundJobRepository.InsertAsync( + new BackgroundJobRecord(_testData.JobId3) + { + JobName = "TestJobName", + JobArgs = "{ value: 3 }", + NextTryTime = _clock.Now, + Priority = BackgroundJobPriority.BelowNormal, + IsAbandoned = false, + LastTryTime = _clock.Now.Subtract(TimeSpan.FromMinutes(60)), + CreationTime = _clock.Now.Subtract(TimeSpan.FromMinutes(90)), + TryCount = 2 + } + ); } -} \ No newline at end of file +}