Browse Source

use file-scoped namespacing for backgroundJobs module

pull/10696/head
Ahmet Çotur 5 years ago
parent
commit
bd939aaf7e
  1. 29
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/DemoAppHangfireModule.cs
  2. 27
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/Program.cs
  3. 17
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz/DemoAppQuartzModule.cs
  4. 27
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.Quartz/Program.cs
  5. 17
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.RabbitMq/DemoAppRabbitMqModule.cs
  6. 27
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.RabbitMq/Program.cs
  7. 21
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Db/DemoAppDbContext.cs
  8. 31
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Db/DemoAppDbContextFactory.cs
  9. 55
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/DemoAppModule.cs
  10. 66
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20201013055401_Initial.cs
  11. 27
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Program.cs
  12. 9
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain.Shared/Volo/Abp/BackgroundJobs/AbpBackgroundJobsDomainSharedModule.cs
  13. 23
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain.Shared/Volo/Abp/BackgroundJobs/BackgroundJobRecordConsts.cs
  14. 27
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/AbpBackgroundJobsDomainModule.cs
  15. 107
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobRecord.cs
  16. 85
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobStore.cs
  17. 13
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobsDbProperties.cs
  18. 19
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobsDomainAutoMapperProfile.cs
  19. 9
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/IBackgroundJobRepository.cs
  20. 25
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/AbpBackgroundJobsEntityFrameworkCoreModule.cs
  21. 29
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/BackgroundJobsDbContext.cs
  22. 51
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/BackgroundJobsDbContextModelCreatingExtensions.cs
  23. 53
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/EfCoreBackgroundJobRepository.cs
  24. 13
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/IBackgroundJobsDbContext.cs
  25. 23
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.Installer/Volo/Abp/BackgroundJobs/AbpBackgroundJobsInstallerModule.cs
  26. 29
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.Installer/Volo/Abp/BackgroundJobs/BackgroundJobsInstallerPipelineBuilder.cs
  27. 23
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/AbpBackgroundJobsMongoDbModule.cs
  28. 21
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobsMongoDbContext.cs
  29. 21
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobsMongoDbContextExtensions.cs
  30. 13
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/IBackgroundJobsMongoDbContext.cs
  31. 53
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs
  32. 15
      modules/background-jobs/test/Volo.Abp.BackgroundJobs.Domain.Tests/Volo/Abp/BackgroundJobs/AbpBackgroundJobsDomainTestModule.cs
  33. 49
      modules/background-jobs/test/Volo.Abp.BackgroundJobs.Domain.Tests/Volo/Abp/BackgroundJobs/BackgroundJobStore_Tests.cs
  34. 9
      modules/background-jobs/test/Volo.Abp.BackgroundJobs.Domain.Tests/Volo/Abp/BackgroundJobs/BackgroundJobsDomainTestBase.cs
  35. 53
      modules/background-jobs/test/Volo.Abp.BackgroundJobs.EntityFrameworkCore.Tests/Volo/Abp/BackgroundJobs/EntityFrameworkCore/AbpBackgroundJobsEntityFrameworkCoreTestModule.cs
  36. 7
      modules/background-jobs/test/Volo.Abp.BackgroundJobs.EntityFrameworkCore.Tests/Volo/Abp/BackgroundJobs/EntityFrameworkCore/BackgroundJobRepositoryTests.cs
  37. 33
      modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/AbpBackgroundJobsMongoDbTestModule.cs
  38. 9
      modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobRepositoryTests.cs
  39. 27
      modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/MongoDbFixture.cs
  40. 13
      modules/background-jobs/test/Volo.Abp.BackgroundJobs.MongoDB.Tests/Volo/Abp/BackgroundJobs/MongoDB/MongoTestCollection.cs
  41. 47
      modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/AbpBackgroundJobsTestBaseModule.cs
  42. 43
      modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobRepository_Tests.cs
  43. 13
      modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobsTestBase.cs
  44. 13
      modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobsTestData.cs
  45. 115
      modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobsTestDataBuilder.cs

29
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<IGlobalConfiguration>(hangfireConfiguration =>
{
hangfireConfiguration.UseSqlServerStorage(configuration.GetConnectionString("Default"));
});
}
context.Services.PreConfigure<IGlobalConfiguration>(hangfireConfiguration =>
{
hangfireConfiguration.UseSqlServerStorage(configuration.GetConnectionString("Default"));
});
}
}

27
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<DemoAppHangfireModule>(options =>
{
options.UseAutofac();
}))
{
using (var application = AbpApplicationFactory.Create<DemoAppHangfireModule>(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();
}
}
}

17
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
{
}
}

27
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<DemoAppQuartzModule>(options =>
{
options.UseAutofac();
}))
{
using (var application = AbpApplicationFactory.Create<DemoAppQuartzModule>(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();
}
}
}

17
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
{
}
}

27
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<DemoAppRabbitMqModule>(options =>
{
options.UseAutofac();
}))
{
using (var application = AbpApplicationFactory.Create<DemoAppRabbitMqModule>(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();
}
}
}

21
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<DemoAppDbContext>
{
public class DemoAppDbContext : AbpDbContext<DemoAppDbContext>
public DemoAppDbContext(DbContextOptions<DemoAppDbContext> options)
: base(options)
{
public DemoAppDbContext(DbContextOptions<DemoAppDbContext> 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();
}
}

31
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<DemoAppDbContext>
{
public class DemoAppDbContextFactory : IDesignTimeDbContextFactory<DemoAppDbContext>
public DemoAppDbContext CreateDbContext(string[] args)
{
public DemoAppDbContext CreateDbContext(string[] args)
{
var configuration = BuildConfiguration();
var configuration = BuildConfiguration();
var builder = new DbContextOptionsBuilder<DemoAppDbContext>()
.UseSqlServer(configuration.GetConnectionString("Default"));
var builder = new DbContextOptionsBuilder<DemoAppDbContext>()
.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();
}
}

55
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<AbpDbContextOptions>(options =>
{
Configure<AbpDbContextOptions>(options =>
options.Configure(opts =>
{
options.Configure(opts =>
{
opts.UseSqlServer();
});
opts.UseSqlServer();
});
});
Configure<AbpBackgroundJobWorkerOptions>(options =>
{
Configure<AbpBackgroundJobWorkerOptions>(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<ILoggerFactory>()
// .AddConsole(LogLevel.Debug);
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
//TODO: Configure console logging
//context
// .ServiceProvider
// .GetRequiredService<ILoggerFactory>()
// .AddConsole(LogLevel.Debug);
}
}

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

27
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<DemoAppModule>(options =>
{
options.UseAutofac();
}))
{
using (var application = AbpApplicationFactory.Create<DemoAppModule>(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();
}
}
}

9
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
{
}
}

23
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
{
/// <summary>
/// Default value: 128
/// </summary>
public static int MaxJobNameLength { get; set; } = 128;
/// <summary>
/// Default value: 128
/// </summary>
public static int MaxJobNameLength { get; set; } = 128;
/// <summary>
/// Default value: 1024 * 1024
/// </summary>
public static int MaxJobArgsLength { get; set; } = 1024 * 1024;
}
/// <summary>
/// Default value: 1024 * 1024
/// </summary>
public static int MaxJobArgsLength { get; set; } = 1024 * 1024;
}

27
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<AbpBackgroundJobsDomainModule>();
Configure<AbpAutoMapperOptions>(options =>
{
context.Services.AddAutoMapperObjectMapper<AbpBackgroundJobsDomainModule>();
Configure<AbpAutoMapperOptions>(options =>
{
options.AddProfile<BackgroundJobsDomainAutoMapperProfile>(validate: true);
});
}
options.AddProfile<BackgroundJobsDomainAutoMapperProfile>(validate: true);
});
}
}

107
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<Guid>, IHasCreationTime
{
public class BackgroundJobRecord : AggregateRoot<Guid>, IHasCreationTime
/// <summary>
/// Type of the job.
/// It's AssemblyQualifiedName of job type.
/// </summary>
public virtual string JobName { get; set; }
/// <summary>
/// Job arguments as serialized string.
/// </summary>
public virtual string JobArgs { get; set; }
/// <summary>
/// Try count of this job.
/// A job is re-tried if it fails.
/// </summary>
public virtual short TryCount { get; set; }
/// <summary>
/// Creation time of this job.
/// </summary>
public virtual DateTime CreationTime { get; set; }
/// <summary>
/// Next try time of this job.
/// </summary>
public virtual DateTime NextTryTime { get; set; }
/// <summary>
/// Last try time of this job.
/// </summary>
public virtual DateTime? LastTryTime { get; set; }
/// <summary>
/// This is true if this job is continuously failed and will not be executed again.
/// </summary>
public virtual bool IsAbandoned { get; set; }
/// <summary>
/// Priority of this job.
/// </summary>
public virtual BackgroundJobPriority Priority { get; set; }
protected BackgroundJobRecord()
{
}
public BackgroundJobRecord(Guid id)
: base(id)
{
/// <summary>
/// Type of the job.
/// It's AssemblyQualifiedName of job type.
/// </summary>
public virtual string JobName { get; set; }
/// <summary>
/// Job arguments as serialized string.
/// </summary>
public virtual string JobArgs { get; set; }
/// <summary>
/// Try count of this job.
/// A job is re-tried if it fails.
/// </summary>
public virtual short TryCount { get; set; }
/// <summary>
/// Creation time of this job.
/// </summary>
public virtual DateTime CreationTime { get; set; }
/// <summary>
/// Next try time of this job.
/// </summary>
public virtual DateTime NextTryTime { get; set; }
/// <summary>
/// Last try time of this job.
/// </summary>
public virtual DateTime? LastTryTime { get; set; }
/// <summary>
/// This is true if this job is continuously failed and will not be executed again.
/// </summary>
public virtual bool IsAbandoned { get; set; }
/// <summary>
/// Priority of this job.
/// </summary>
public virtual BackgroundJobPriority Priority { get; set; }
protected BackgroundJobRecord()
{
}
public BackgroundJobRecord(Guid id)
: base(id)
{
}
}
}

85
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<AbpBackgroundJobsDomainModule> ObjectMapper { get; }
protected IObjectMapper<AbpBackgroundJobsDomainModule> ObjectMapper { get; }
public BackgroundJobStore(
IBackgroundJobRepository backgroundJobRepository,
IObjectMapper<AbpBackgroundJobsDomainModule> objectMapper)
{
ObjectMapper = objectMapper;
BackgroundJobRepository = backgroundJobRepository;
}
public BackgroundJobStore(
IBackgroundJobRepository backgroundJobRepository,
IObjectMapper<AbpBackgroundJobsDomainModule> objectMapper)
{
ObjectMapper = objectMapper;
BackgroundJobRepository = backgroundJobRepository;
}
public virtual async Task<BackgroundJobInfo> FindAsync(Guid jobId)
{
return ObjectMapper.Map<BackgroundJobRecord, BackgroundJobInfo>(
await BackgroundJobRepository.FindAsync(jobId)
);
}
public virtual async Task<BackgroundJobInfo> FindAsync(Guid jobId)
{
return ObjectMapper.Map<BackgroundJobRecord, BackgroundJobInfo>(
await BackgroundJobRepository.FindAsync(jobId)
);
}
public virtual async Task InsertAsync(BackgroundJobInfo jobInfo)
{
await BackgroundJobRepository.InsertAsync(
ObjectMapper.Map<BackgroundJobInfo, BackgroundJobRecord>(jobInfo)
);
}
public virtual async Task InsertAsync(BackgroundJobInfo jobInfo)
{
await BackgroundJobRepository.InsertAsync(
ObjectMapper.Map<BackgroundJobInfo, BackgroundJobRecord>(jobInfo)
);
}
public virtual async Task<List<BackgroundJobInfo>> GetWaitingJobsAsync(int maxResultCount)
{
return ObjectMapper.Map<List<BackgroundJobRecord>, List<BackgroundJobInfo>>(
await BackgroundJobRepository.GetWaitingListAsync(maxResultCount)
);
}
public virtual async Task<List<BackgroundJobInfo>> GetWaitingJobsAsync(int maxResultCount)
{
return ObjectMapper.Map<List<BackgroundJobRecord>, List<BackgroundJobInfo>>(
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);
}
}

13
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";
}

19
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<BackgroundJobInfo, BackgroundJobRecord>()
.ConstructUsing(x => new BackgroundJobRecord(x.Id))
.Ignore(record => record.ConcurrencyStamp)
.Ignore(record => record.ExtraProperties);
CreateMap<BackgroundJobInfo, BackgroundJobRecord>()
.ConstructUsing(x => new BackgroundJobRecord(x.Id))
.Ignore(record => record.ConcurrencyStamp)
.Ignore(record => record.ExtraProperties);
CreateMap<BackgroundJobRecord, BackgroundJobInfo>();
}
CreateMap<BackgroundJobRecord, BackgroundJobInfo>();
}
}

9
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<BackgroundJobRecord, Guid>
{
public interface IBackgroundJobRepository : IBasicRepository<BackgroundJobRecord, Guid>
{
Task<List<BackgroundJobRecord>> GetWaitingListAsync(int maxResultCount, CancellationToken cancellationToken = default);
}
Task<List<BackgroundJobRecord>> GetWaitingListAsync(int maxResultCount, CancellationToken cancellationToken = default);
}

25
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<BackgroundJobsDbContext>(options =>
{
context.Services.AddAbpDbContext<BackgroundJobsDbContext>(options =>
{
options.AddRepository<BackgroundJobRecord, EfCoreBackgroundJobRepository>();
});
}
options.AddRepository<BackgroundJobRecord, EfCoreBackgroundJobRepository>();
});
}
}
}

29
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<BackgroundJobsDbContext>, IBackgroundJobsDbContext
{
[IgnoreMultiTenancy]
[ConnectionStringName(BackgroundJobsDbProperties.ConnectionStringName)]
public class BackgroundJobsDbContext : AbpDbContext<BackgroundJobsDbContext>, IBackgroundJobsDbContext
{
public DbSet<BackgroundJobRecord> BackgroundJobs { get; set; }
public DbSet<BackgroundJobRecord> BackgroundJobs { get; set; }
public BackgroundJobsDbContext(DbContextOptions<BackgroundJobsDbContext> options)
: base(options)
{
public BackgroundJobsDbContext(DbContextOptions<BackgroundJobsDbContext> 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();
}
}

51
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<BackgroundJobRecord>(b =>
{
b.ToTable(BackgroundJobsDbProperties.DbTablePrefix + "BackgroundJobs", BackgroundJobsDbProperties.DbSchema);
builder.Entity<BackgroundJobRecord>(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<BackgroundJobsDbContext>();
}
builder.TryConfigureObjectExtensions<BackgroundJobsDbContext>();
}
}

53
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<IBackgroundJobsDbContext, BackgroundJobRecord, Guid>, IBackgroundJobRepository
{
public class EfCoreBackgroundJobRepository : EfCoreRepository<IBackgroundJobsDbContext, BackgroundJobRecord, Guid>, IBackgroundJobRepository
{
protected IClock Clock { get; }
protected IClock Clock { get; }
public EfCoreBackgroundJobRepository(
IDbContextProvider<IBackgroundJobsDbContext> dbContextProvider,
IClock clock)
: base(dbContextProvider)
{
Clock = clock;
}
public EfCoreBackgroundJobRepository(
IDbContextProvider<IBackgroundJobsDbContext> dbContextProvider,
IClock clock)
: base(dbContextProvider)
{
Clock = clock;
}
public virtual async Task<List<BackgroundJobRecord>> GetWaitingListAsync(
int maxResultCount,
CancellationToken cancellationToken = default)
{
return await (await GetWaitingListQueryAsync(maxResultCount)).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<BackgroundJobRecord>> GetWaitingListAsync(
int maxResultCount,
CancellationToken cancellationToken = default)
{
return await (await GetWaitingListQueryAsync(maxResultCount)).ToListAsync(GetCancellationToken(cancellationToken));
}
protected virtual async Task<IQueryable<BackgroundJobRecord>> 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<IQueryable<BackgroundJobRecord>> 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);
}
}

13
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<BackgroundJobRecord> BackgroundJobs { get; }
}
DbSet<BackgroundJobRecord> BackgroundJobs { get; }
}

23
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<AbpVirtualFileSystemOptions>(options =>
{
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<AbpBackgroundJobsInstallerModule>();
});
}
options.FileSets.AddEmbedded<AbpBackgroundJobsInstallerModule>();
});
}
}

29
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<ModuleInstallingPipeline> BuildAsync(ModuleInstallingContext context)
{
public async Task<ModuleInstallingPipeline> 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);
}
}

23
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<BackgroundJobsMongoDbContext>(options =>
{
context.Services.AddMongoDbContext<BackgroundJobsMongoDbContext>(options =>
{
options.AddRepository<BackgroundJobRecord, MongoBackgroundJobRepository>();
});
}
options.AddRepository<BackgroundJobRecord, MongoBackgroundJobRepository>();
});
}
}

21
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<BackgroundJobRecord> BackgroundJobs { get; set; }
public IMongoCollection<BackgroundJobRecord> 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();
}
}

21
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<BackgroundJobRecord>(b =>
{
b.CollectionName = BackgroundJobsDbProperties.DbTablePrefix + "BackgroundJobs";
});
}
builder.Entity<BackgroundJobRecord>(b =>
{
b.CollectionName = BackgroundJobsDbProperties.DbTablePrefix + "BackgroundJobs";
});
}
}

13
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<BackgroundJobRecord> BackgroundJobs { get; }
}
IMongoCollection<BackgroundJobRecord> BackgroundJobs { get; }
}

53
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<IBackgroundJobsMongoDbContext, BackgroundJobRecord, Guid>, IBackgroundJobRepository
{
public class MongoBackgroundJobRepository : MongoDbRepository<IBackgroundJobsMongoDbContext, BackgroundJobRecord, Guid>, IBackgroundJobRepository
{
protected IClock Clock { get; }
protected IClock Clock { get; }
public MongoBackgroundJobRepository(
IMongoDbContextProvider<IBackgroundJobsMongoDbContext> dbContextProvider,
IClock clock)
: base(dbContextProvider)
{
Clock = clock;
}
public MongoBackgroundJobRepository(
IMongoDbContextProvider<IBackgroundJobsMongoDbContext> dbContextProvider,
IClock clock)
: base(dbContextProvider)
{
Clock = clock;
}
public virtual async Task<List<BackgroundJobRecord>> GetWaitingListAsync(
int maxResultCount,
CancellationToken cancellationToken = default)
{
return await (await GetWaitingListQuery(maxResultCount)).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<BackgroundJobRecord>> GetWaitingListAsync(
int maxResultCount,
CancellationToken cancellationToken = default)
{
return await (await GetWaitingListQuery(maxResultCount)).ToListAsync(GetCancellationToken(cancellationToken));
}
protected virtual async Task<IMongoQueryable<BackgroundJobRecord>> 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<IMongoQueryable<BackgroundJobRecord>> 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);
}
}

15
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
{
}
}

49
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<IBackgroundJobStore>();
}
public BackgroundJobStore_Tests()
{
_backgroundJobStore = GetRequiredService<IBackgroundJobStore>();
}
[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);
}
}

9
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<AbpBackgroundJobsDomainTestModule>
{
public abstract class BackgroundJobsDomainTestBase : BackgroundJobsTestBase<AbpBackgroundJobsDomainTestModule>
{
}
}
}

53
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<AbpDbContextOptions>(options =>
Configure<AbpDbContextOptions>(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<BackgroundJobsDbContext>().UseSqlite(connection).Options
).GetService<IRelationalDatabaseCreator>().CreateTables();
new BackgroundJobsDbContext(
new DbContextOptionsBuilder<BackgroundJobsDbContext>().UseSqlite(connection).Options
).GetService<IRelationalDatabaseCreator>().CreateTables();
return connection;
}
return connection;
}
}

7
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<AbpBackgroundJobsEntityFrameworkCoreTestModule>
{
public class BackgroundJobRepositoryTests : BackgroundJobRepository_Tests<AbpBackgroundJobsEntityFrameworkCoreTestModule>
{
}
}

33
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<AbpDbConnectionOptions>(options =>
{
options.ConnectionStrings.Default = connectionString;
});
}
Configure<AbpDbConnectionOptions>(options =>
{
options.ConnectionStrings.Default = connectionString;
});
}
}

9
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<AbpBackgroundJobsMongoDbTestModule>
{
[Collection((MongoTestCollection.Name))]
public class BackgroundJobRepositoryTests : BackgroundJobRepository_Tests<AbpBackgroundJobsMongoDbTestModule>
{
}
}

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

13
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<MongoDbFixture>
{
[CollectionDefinition(Name)]
public class MongoTestCollection : ICollectionFixture<MongoDbFixture>
{
public const string Name = "MongoDB Collection";
}
}
public const string Name = "MongoDB Collection";
}

47
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<AbpBackgroundJobOptions>(options =>
{
Configure<AbpBackgroundJobOptions>(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<BackgroundJobsTestDataBuilder>()
.BuildAsync());
}
AsyncHelper.RunSync(() => scope.ServiceProvider
.GetRequiredService<BackgroundJobsTestDataBuilder>()
.BuildAsync());
}
}
}

43
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<TStartupModule> : BackgroundJobsTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
public abstract class BackgroundJobRepository_Tests<TStartupModule> : BackgroundJobsTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
private readonly IBackgroundJobRepository _backgroundJobRepository;
private readonly IClock _clock;
private readonly IBackgroundJobRepository _backgroundJobRepository;
private readonly IClock _clock;
protected BackgroundJobRepository_Tests()
{
_backgroundJobRepository = GetRequiredService<IBackgroundJobRepository>();
_clock = GetRequiredService<IClock>();
}
protected BackgroundJobRepository_Tests()
{
_backgroundJobRepository = GetRequiredService<IBackgroundJobRepository>();
_clock = GetRequiredService<IClock>();
}
[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
}
}

13
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<TStartupModule> : AbpIntegratedTest<TStartupModule>
where TStartupModule : IAbpModule
{
public abstract class BackgroundJobsTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule>
where TStartupModule : IAbpModule
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
}
options.UseAutofac();
}
}

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

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

Loading…
Cancel
Save