Browse Source

Merge pull request #24683 from abpframework/auto-merge/rel-10-1/4291

Merge branch dev with rel-10.1
pull/24694/head
Ma Liming 3 weeks ago
committed by GitHub
parent
commit
02f4e5a1d9
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 10
      framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/AbpHangfirePeriodicBackgroundWorkerAdapterOptions.cs
  2. 101
      framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireBackgroundWorkerManager.cs
  3. 19
      framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfirePeriodicBackgroundWorkerAdapter.cs
  4. 33
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/DemoAppHangfireModule.cs
  5. 22
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/TestWorker.cs
  6. 2
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/Volo.Abp.BackgroundJobs.DemoApp.HangFire.csproj
  7. 41
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20201013055401_Initial.cs
  8. 40
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20260119064307_Initial.Designer.cs
  9. 49
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20260119064307_Initial.cs
  10. 37
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/DemoAppDbContextModelSnapshot.cs

10
framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/AbpHangfirePeriodicBackgroundWorkerAdapterOptions.cs

@ -0,0 +1,10 @@
using System;
namespace Volo.Abp.BackgroundWorkers.Hangfire;
public class AbpHangfirePeriodicBackgroundWorkerAdapterOptions
{
public TimeZoneInfo TimeZone { get; set; } = TimeZoneInfo.Utc;
public string Queue { get; set; } = default!;
}

101
framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireBackgroundWorkerManager.cs

@ -5,7 +5,9 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Hangfire; using Hangfire;
using Hangfire.Common; using Hangfire.Common;
using Hangfire.Storage;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.DynamicProxy; using Volo.Abp.DynamicProxy;
@ -30,8 +32,9 @@ public class HangfireBackgroundWorkerManager : BackgroundWorkerManager, ISinglet
BackgroundJobServer = ServiceProvider.GetRequiredService<AbpHangfireBackgroundJobServer>(); BackgroundJobServer = ServiceProvider.GetRequiredService<AbpHangfireBackgroundJobServer>();
} }
public async override Task AddAsync(IBackgroundWorker worker, CancellationToken cancellationToken = default) public override async Task AddAsync(IBackgroundWorker worker, CancellationToken cancellationToken = default)
{ {
var logger = ServiceProvider.GetRequiredService<ILogger<HangfireBackgroundWorkerManager>>();
var abpHangfireOptions = ServiceProvider.GetRequiredService<IOptions<AbpHangfireOptions>>().Value; var abpHangfireOptions = ServiceProvider.GetRequiredService<IOptions<AbpHangfireOptions>>().Value;
var defaultQueuePrefix = abpHangfireOptions.DefaultQueuePrefix; var defaultQueuePrefix = abpHangfireOptions.DefaultQueuePrefix;
var defaultQueue = abpHangfireOptions.DefaultQueue; var defaultQueue = abpHangfireOptions.DefaultQueue;
@ -42,54 +45,90 @@ public class HangfireBackgroundWorkerManager : BackgroundWorkerManager, ISinglet
{ {
var unProxyWorker = ProxyHelper.UnProxy(hangfireBackgroundWorker); var unProxyWorker = ProxyHelper.UnProxy(hangfireBackgroundWorker);
RecurringJob.AddOrUpdate( var queueName = hangfireBackgroundWorker.Queue.IsNullOrWhiteSpace() ? defaultQueue : defaultQueuePrefix + hangfireBackgroundWorker.Queue;
hangfireBackgroundWorker.RecurringJobId, if (!JobStorage.Current.HasFeature(JobStorageFeatures.JobQueueProperty))
hangfireBackgroundWorker.Queue.IsNullOrWhiteSpace() ? defaultQueue : defaultQueuePrefix + hangfireBackgroundWorker.Queue, {
() => ((IHangfireBackgroundWorker)unProxyWorker).DoWorkAsync(cancellationToken), logger.LogError($"Current storage doesn't support specifying queues({queueName}) directly for a specific job. Please use the QueueAttribute instead.");
hangfireBackgroundWorker.CronExpression, RecurringJob.AddOrUpdate(
new RecurringJobOptions hangfireBackgroundWorker.RecurringJobId,
{ () => ((IHangfireBackgroundWorker)unProxyWorker).DoWorkAsync(cancellationToken),
TimeZone = hangfireBackgroundWorker.TimeZone hangfireBackgroundWorker.CronExpression,
}); new RecurringJobOptions
{
TimeZone = hangfireBackgroundWorker.TimeZone
});
}
else
{
RecurringJob.AddOrUpdate(
hangfireBackgroundWorker.RecurringJobId,
queueName,
() => ((IHangfireBackgroundWorker)unProxyWorker).DoWorkAsync(cancellationToken),
hangfireBackgroundWorker.CronExpression,
new RecurringJobOptions
{
TimeZone = hangfireBackgroundWorker.TimeZone
});
}
break; break;
} }
case AsyncPeriodicBackgroundWorkerBase or PeriodicBackgroundWorkerBase: case AsyncPeriodicBackgroundWorkerBase or PeriodicBackgroundWorkerBase:
{ {
int? period = null; int? period = null;
string? CronExpression = null; string? cronExpression = null;
if (worker is AsyncPeriodicBackgroundWorkerBase asyncPeriodicBackgroundWorkerBase) switch (worker)
{ {
case AsyncPeriodicBackgroundWorkerBase asyncPeriodicBackgroundWorkerBase:
period = asyncPeriodicBackgroundWorkerBase.Period; period = asyncPeriodicBackgroundWorkerBase.Period;
CronExpression = asyncPeriodicBackgroundWorkerBase.CronExpression; cronExpression = asyncPeriodicBackgroundWorkerBase.CronExpression;
} break;
else if (worker is PeriodicBackgroundWorkerBase periodicBackgroundWorkerBase) case PeriodicBackgroundWorkerBase periodicBackgroundWorkerBase:
{
period = periodicBackgroundWorkerBase.Period; period = periodicBackgroundWorkerBase.Period;
CronExpression = periodicBackgroundWorkerBase.CronExpression; cronExpression = periodicBackgroundWorkerBase.CronExpression;
break;
} }
if (period == null && CronExpression.IsNullOrWhiteSpace()) if (period == null && cronExpression.IsNullOrWhiteSpace())
{ {
logger.LogError(
$"Cannot add periodic background worker {worker.GetType().FullName} to Hangfire scheduler, because both Period and CronExpression are not set. " +
"You can either set Period or CronExpression property of the worker."
);
return; return;
} }
var adapterType = typeof(HangfirePeriodicBackgroundWorkerAdapter<>).MakeGenericType(ProxyHelper.GetUnProxiedType(worker)); var workerAdapter = (ServiceProvider.GetRequiredService(typeof(HangfirePeriodicBackgroundWorkerAdapter<>).MakeGenericType(ProxyHelper.GetUnProxiedType(worker))) as IHangfireBackgroundWorker)!;
var workerAdapter = (Activator.CreateInstance(adapterType) as IHangfireBackgroundWorker)!;
Expression<Func<Task>> methodCall = () => workerAdapter.DoWorkAsync(cancellationToken); Expression<Func<Task>> methodCall = () => workerAdapter.DoWorkAsync(cancellationToken);
var recurringJobId = !workerAdapter.RecurringJobId.IsNullOrWhiteSpace() ? workerAdapter.RecurringJobId : GetRecurringJobId(worker, methodCall); var recurringJobId = !workerAdapter.RecurringJobId.IsNullOrWhiteSpace() ? workerAdapter.RecurringJobId : GetRecurringJobId(worker, methodCall);
RecurringJob.AddOrUpdate( var queueName = workerAdapter.Queue.IsNullOrWhiteSpace() ? defaultQueue : defaultQueuePrefix + workerAdapter.Queue;
recurringJobId, if (!JobStorage.Current.HasFeature(JobStorageFeatures.JobQueueProperty))
workerAdapter.Queue.IsNullOrWhiteSpace() ? defaultQueue : defaultQueuePrefix + workerAdapter.Queue, {
methodCall, logger.LogError($"Current storage doesn't support specifying queues({queueName}) directly for a specific job. Please use the QueueAttribute instead.");
CronExpression ?? GetCron(period!.Value), RecurringJob.AddOrUpdate(
new RecurringJobOptions recurringJobId,
{ methodCall,
TimeZone = workerAdapter.TimeZone cronExpression ?? GetCron(period!.Value),
}); new RecurringJobOptions
{
TimeZone = workerAdapter.TimeZone
});
}
else
{
RecurringJob.AddOrUpdate(
recurringJobId,
queueName,
methodCall,
cronExpression ?? GetCron(period!.Value),
new RecurringJobOptions
{
TimeZone = workerAdapter.TimeZone
});
}
break; break;
} }
default: default:
@ -98,7 +137,7 @@ public class HangfireBackgroundWorkerManager : BackgroundWorkerManager, ISinglet
} }
} }
private readonly static MethodInfo? GetRecurringJobIdMethodInfo = typeof(RecurringJob).GetMethod("GetRecurringJobId", BindingFlags.NonPublic | BindingFlags.Static); private static readonly MethodInfo? GetRecurringJobIdMethodInfo = typeof(RecurringJob).GetMethod("GetRecurringJobId", BindingFlags.NonPublic | BindingFlags.Static);
protected virtual string? GetRecurringJobId(IBackgroundWorker worker, Expression<Func<Task>> methodCall) protected virtual string? GetRecurringJobId(IBackgroundWorker worker, Expression<Func<Task>> methodCall)
{ {
string? recurringJobId = null; string? recurringJobId = null;

19
framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfirePeriodicBackgroundWorkerAdapter.cs

@ -1,7 +1,9 @@
using System.Reflection; using System;
using System.Reflection;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
namespace Volo.Abp.BackgroundWorkers.Hangfire; namespace Volo.Abp.BackgroundWorkers.Hangfire;
@ -11,14 +13,17 @@ public class HangfirePeriodicBackgroundWorkerAdapter<TWorker> : HangfireBackgrou
private readonly MethodInfo _doWorkAsyncMethod; private readonly MethodInfo _doWorkAsyncMethod;
private readonly MethodInfo _doWorkMethod; private readonly MethodInfo _doWorkMethod;
public HangfirePeriodicBackgroundWorkerAdapter() public HangfirePeriodicBackgroundWorkerAdapter(IOptions<AbpHangfirePeriodicBackgroundWorkerAdapterOptions> options)
{ {
TimeZone = options.Value.TimeZone;
Queue = options.Value.Queue;
RecurringJobId = BackgroundWorkerNameAttribute.GetNameOrNull<TWorker>();
_doWorkAsyncMethod = typeof(TWorker).GetMethod("DoWorkAsync", BindingFlags.Instance | BindingFlags.NonPublic)!; _doWorkAsyncMethod = typeof(TWorker).GetMethod("DoWorkAsync", BindingFlags.Instance | BindingFlags.NonPublic)!;
_doWorkMethod = typeof(TWorker).GetMethod("DoWork", BindingFlags.Instance | BindingFlags.NonPublic)!; _doWorkMethod = typeof(TWorker).GetMethod("DoWork", BindingFlags.Instance | BindingFlags.NonPublic)!;
RecurringJobId = BackgroundWorkerNameAttribute.GetNameOrNull<TWorker>();
} }
public async override Task DoWorkAsync(CancellationToken cancellationToken = default) public override async Task DoWorkAsync(CancellationToken cancellationToken = default)
{ {
var workerContext = new PeriodicBackgroundWorkerContext(ServiceProvider, cancellationToken); var workerContext = new PeriodicBackgroundWorkerContext(ServiceProvider, cancellationToken);
var worker = ServiceProvider.GetRequiredService<TWorker>(); var worker = ServiceProvider.GetRequiredService<TWorker>();
@ -26,13 +31,11 @@ public class HangfirePeriodicBackgroundWorkerAdapter<TWorker> : HangfireBackgrou
switch (worker) switch (worker)
{ {
case AsyncPeriodicBackgroundWorkerBase asyncPeriodicBackgroundWorker: case AsyncPeriodicBackgroundWorkerBase asyncPeriodicBackgroundWorker:
await (Task)(_doWorkAsyncMethod.Invoke(asyncPeriodicBackgroundWorker, new object[] { workerContext })!); await (Task)(_doWorkAsyncMethod.Invoke(asyncPeriodicBackgroundWorker, [workerContext])!);
break; break;
case PeriodicBackgroundWorkerBase periodicBackgroundWorker: case PeriodicBackgroundWorkerBase periodicBackgroundWorker:
_doWorkMethod.Invoke(periodicBackgroundWorker, new object[] { workerContext }); _doWorkMethod.Invoke(periodicBackgroundWorker, [workerContext]);
break; break;
} }
} }
} }

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

@ -1,17 +1,23 @@
using Hangfire; using System;
using System.Threading.Tasks;
using Hangfire;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Autofac; using Volo.Abp.Autofac;
using Volo.Abp.BackgroundJobs.DemoApp.Shared; using Volo.Abp.BackgroundJobs.DemoApp.Shared;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Volo.Abp.BackgroundJobs.Hangfire; using Volo.Abp.BackgroundJobs.Hangfire;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.BackgroundWorkers.Hangfire;
using Volo.Abp.Hangfire;
namespace Volo.Abp.BackgroundJobs.DemoApp.HangFire; namespace Volo.Abp.BackgroundJobs.DemoApp.HangFire;
[DependsOn( [DependsOn(
typeof(DemoAppSharedModule), typeof(DemoAppSharedModule),
typeof(AbpAutofacModule), typeof(AbpAutofacModule),
typeof(AbpBackgroundJobsHangfireModule) typeof(AbpBackgroundJobsHangfireModule),
typeof(AbpBackgroundWorkersHangfireModule)
)] )]
public class DemoAppHangfireModule : AbpModule public class DemoAppHangfireModule : AbpModule
{ {
@ -24,4 +30,27 @@ public class DemoAppHangfireModule : AbpModule
hangfireConfiguration.UseSqlServerStorage(configuration.GetConnectionString("Default")); hangfireConfiguration.UseSqlServerStorage(configuration.GetConnectionString("Default"));
}); });
} }
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpHangfireOptions>(options =>
{
options.ServerOptions = new BackgroundJobServerOptions
{
Queues = new []{ "default", "my-default" }
};
});
Configure<AbpHangfirePeriodicBackgroundWorkerAdapterOptions>(options =>
{
options.TimeZone = TimeZoneInfo.Local;
options.Queue = "my-default";
});
}
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
{
var backgroundWorkerManager = context.ServiceProvider.GetRequiredService<IBackgroundWorkerManager>();
await backgroundWorkerManager.AddAsync(context.ServiceProvider.GetRequiredService<TestWorker>());
}
} }

22
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.HangFire/TestWorker.cs

@ -0,0 +1,22 @@
using System;
using System.Threading.Tasks;
using Hangfire;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.Threading;
namespace Volo.Abp.BackgroundJobs.DemoApp.HangFire;
public class TestWorker : AsyncPeriodicBackgroundWorkerBase
{
public TestWorker(AbpAsyncTimer timer, IServiceScopeFactory serviceScopeFactory)
: base(timer, serviceScopeFactory)
{
CronExpression = Cron.Minutely();
}
protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
{
Console.WriteLine($"[{DateTime.Now}] TestWorker executed.");
}
}

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

@ -7,8 +7,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Hangfire.SqlServer" /> <PackageReference Include="Hangfire.SqlServer" />
<PackageReference Include="Microsoft.Data.SqlClient" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> <ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.BackgroundJobs.HangFire\Volo.Abp.BackgroundJobs.HangFire.csproj" /> <ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.BackgroundJobs.HangFire\Volo.Abp.BackgroundJobs.HangFire.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.BackgroundWorkers.Hangfire\Volo.Abp.BackgroundWorkers.Hangfire.csproj" />
<ProjectReference Include="..\Volo.Abp.BackgroundJobs.DemoApp.Shared\Volo.Abp.BackgroundJobs.DemoApp.Shared.csproj" /> <ProjectReference Include="..\Volo.Abp.BackgroundJobs.DemoApp.Shared\Volo.Abp.BackgroundJobs.DemoApp.Shared.csproj" />
</ItemGroup> </ItemGroup>

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

@ -1,41 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations;
public partial class Initial : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "AbpBackgroundJobs",
columns: table => new {
Id = table.Column<Guid>(nullable: false),
ExtraProperties = table.Column<string>(nullable: true),
ConcurrencyStamp = table.Column<string>(maxLength: 40, nullable: true),
JobName = table.Column<string>(maxLength: 128, nullable: false),
JobArgs = table.Column<string>(maxLength: 1048576, nullable: false),
TryCount = table.Column<short>(nullable: false, defaultValue: (short)0),
CreationTime = table.Column<DateTime>(nullable: false),
NextTryTime = table.Column<DateTime>(nullable: false),
LastTryTime = table.Column<DateTime>(nullable: true),
IsAbandoned = table.Column<bool>(nullable: false, defaultValue: false),
Priority = table.Column<byte>(nullable: false, defaultValue: (byte)15)
},
constraints: table =>
{
table.PrimaryKey("PK_AbpBackgroundJobs", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_AbpBackgroundJobs_IsAbandoned_NextTryTime",
table: "AbpBackgroundJobs",
columns: new[] { "IsAbandoned", "NextTryTime" });
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AbpBackgroundJobs");
}
}

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

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

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

@ -0,0 +1,49 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations
{
/// <inheritdoc />
public partial class Initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "AbpBackgroundJobs",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
ApplicationName = table.Column<string>(type: "nvarchar(96)", maxLength: 96, nullable: true),
JobName = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
JobArgs = table.Column<string>(type: "nvarchar(max)", maxLength: 1048576, nullable: false),
TryCount = table.Column<short>(type: "smallint", nullable: false, defaultValue: (short)0),
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
NextTryTime = table.Column<DateTime>(type: "datetime2", nullable: false),
LastTryTime = table.Column<DateTime>(type: "datetime2", nullable: true),
IsAbandoned = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
Priority = table.Column<byte>(type: "tinyint", nullable: false, defaultValue: (byte)15),
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false),
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AbpBackgroundJobs", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_AbpBackgroundJobs_IsAbandoned_NextTryTime",
table: "AbpBackgroundJobs",
columns: new[] { "IsAbandoned", "NextTryTime" });
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AbpBackgroundJobs");
}
}
}

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

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

Loading…
Cancel
Save