diff --git a/framework/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AbpAutoMapperModule.cs b/framework/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AbpAutoMapperModule.cs index e92717ead2..7eb61603b2 100644 --- a/framework/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AbpAutoMapperModule.cs +++ b/framework/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AbpAutoMapperModule.cs @@ -26,7 +26,7 @@ namespace Volo.Abp.AutoMapper context.Services.AddSingleton(_ => mapperAccessor); } - public override void OnApplicationInitialization(ApplicationInitializationContext context) + public override void OnPreApplicationInitialization(ApplicationInitializationContext context) { CreateMappings(context.ServiceProvider); } diff --git a/framework/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AutoMapperObjectMapper.cs b/framework/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AutoMapperObjectMapper.cs index 6a38f0b3aa..73fad64113 100644 --- a/framework/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AutoMapperObjectMapper.cs +++ b/framework/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/AutoMapperObjectMapper.cs @@ -1,5 +1,4 @@ using System; -using AutoMapper; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.DependencyInjection; using Volo.Abp.ObjectMapping; @@ -9,22 +8,22 @@ namespace Volo.Abp.AutoMapper [Dependency(ServiceLifetime.Transient, ReplaceServices = true)] public class AutoMapperObjectMapper : DefaultObjectMapper { - private readonly IMapper _mapper; + protected IMapperAccessor MapperAccessor { get; } - public AutoMapperObjectMapper(IMapperAccessor mapper, IServiceProvider serviceProvider) + public AutoMapperObjectMapper(IMapperAccessor mapperAccessor, IServiceProvider serviceProvider) : base(serviceProvider) { - _mapper = mapper.Mapper; + MapperAccessor = mapperAccessor; } protected override TDestination AutoMap(object source) { - return _mapper.Map(source); + return MapperAccessor.Mapper.Map(source); } protected override TDestination AutoMap(TSource source, TDestination destination) { - return _mapper.Map(source, destination); + return MapperAccessor.Mapper.Map(source, destination); } } } diff --git a/framework/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/MapperAccessor.cs b/framework/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/MapperAccessor.cs index a4be4facb4..3f8d944a3e 100644 --- a/framework/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/MapperAccessor.cs +++ b/framework/src/Volo.Abp.AutoMapper/Volo/Abp/AutoMapper/MapperAccessor.cs @@ -2,7 +2,7 @@ using AutoMapper; namespace Volo.Abp.AutoMapper { - public class MapperAccessor : IMapperAccessor + internal class MapperAccessor : IMapperAccessor { public IMapper Mapper { get; set; } } diff --git a/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobInfo.cs b/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobInfo.cs index 49735e83e0..08cbea12e5 100644 --- a/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobInfo.cs +++ b/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobInfo.cs @@ -37,9 +37,9 @@ namespace Volo.Abp.BackgroundJobs public virtual string JobName { get; set; } /// - /// Job arguments as JSON string. + /// Job arguments as serialized to string. /// - public virtual string JobArgs { get; set; } //TODO: Consider to conver to byte[] + public virtual string JobArgs { get; set; } /// /// Try count of this job. diff --git a/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobOptions.cs b/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobOptions.cs index ad40c0428b..5cf3e622a0 100644 --- a/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobOptions.cs +++ b/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobOptions.cs @@ -3,16 +3,31 @@ using System.Collections.Generic; namespace Volo.Abp.BackgroundJobs { + //TODO: Move options related to default backgroundjob manager to another class + //TODO: Create Volo.Abp.BackgroundJobs.Abstractions package and move abstractions there! + public class BackgroundJobOptions { - //TODO: Consider to automatically register jobs public Dictionary JobTypes { get; } - public bool IsJobExecutionEnabled { get; set; } - + /// + /// Default: true. + /// + public bool IsJobExecutionEnabled { get; set; } = true; + + /// + /// Interval between polling jobs from . + /// Default value: 5000 (5 seconds). + /// + public int JobPollPeriod { get; set; } + + /// + /// Maximum count of jobs to fetch from data store in one loop. + /// + public int MaxJobFetchCount { get; set; } = 1000; + public BackgroundJobOptions() { - IsJobExecutionEnabled = true; JobTypes = new Dictionary(); } diff --git a/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorker.cs b/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorker.cs index 126d48ee42..d8f2ad7367 100644 --- a/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorker.cs +++ b/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorker.cs @@ -1,47 +1,35 @@ -using System; -using System.Threading.Tasks; +using Microsoft.Extensions.Options; using Volo.Abp.BackgroundWorkers; using Volo.Abp.DependencyInjection; -using Volo.Abp.Guids; using Volo.Abp.Threading; -using Volo.Abp.Timing; namespace Volo.Abp.BackgroundJobs { public class BackgroundJobWorker : PeriodicBackgroundWorkerBase, IBackgroundJobWorker, ISingletonDependency { - /// - /// Interval between polling jobs from . - /// Default value: 5000 (5 seconds). - /// - public static int JobPollPeriod { get; set; } //TODO: Move to options - protected IBackgroundJobExecuter JobExecuter { get; } protected IBackgroundJobStore Store { get; } - - static BackgroundJobWorker() - { - JobPollPeriod = 5000; - } - + protected BackgroundJobOptions Options { get; } + /// /// Initializes a new instance of the class. /// public BackgroundJobWorker( IBackgroundJobStore store, AbpTimer timer, - IBackgroundJobExecuter jobExecuter) + IBackgroundJobExecuter jobExecuter, + IOptions options) : base(timer) { JobExecuter = jobExecuter; Store = store; - - Timer.Period = JobPollPeriod; + Options = options.Value; + Timer.Period = Options.JobPollPeriod; } protected override void DoWork() { - var waitingJobs = AsyncHelper.RunSync(() => Store.GetWaitingJobsAsync(1000)); + var waitingJobs = AsyncHelper.RunSync(() => Store.GetWaitingJobsAsync(Options.MaxJobFetchCount)); foreach (var job in waitingJobs) { diff --git a/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/BackgroundWorkerManager.cs b/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/BackgroundWorkerManager.cs index 6c5f890f12..474db34ab7 100644 --- a/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/BackgroundWorkerManager.cs +++ b/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/BackgroundWorkerManager.cs @@ -10,40 +10,40 @@ namespace Volo.Abp.BackgroundWorkers /// public class BackgroundWorkerManager : RunnableBase, IBackgroundWorkerManager, ISingletonDependency, IDisposable { - private readonly List _backgroundJobs; + private readonly List _backgroundWorkers; /// /// Initializes a new instance of the class. /// public BackgroundWorkerManager() { - _backgroundJobs = new List(); + _backgroundWorkers = new List(); } public override void Start() { base.Start(); - _backgroundJobs.ForEach(job => job.Start()); + _backgroundWorkers.ForEach(worker => worker.Start()); } public override void Stop() { - _backgroundJobs.ForEach(job => job.Stop()); + _backgroundWorkers.ForEach(worker => worker.Stop()); base.Stop(); } public override void WaitToStop() { - _backgroundJobs.ForEach(job => job.WaitToStop()); + _backgroundWorkers.ForEach(worker => worker.WaitToStop()); base.WaitToStop(); } public void Add(IBackgroundWorker worker) { - _backgroundJobs.Add(worker); + _backgroundWorkers.Add(worker); if (IsRunning) { diff --git a/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/BackgroundWorkerOptions.cs b/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/BackgroundWorkerOptions.cs index 991e378911..6b368f657a 100644 --- a/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/BackgroundWorkerOptions.cs +++ b/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/BackgroundWorkerOptions.cs @@ -2,6 +2,9 @@ { public class BackgroundWorkerOptions { - public bool IsEnabled { get; set; } + /// + /// Default: true. + /// + public bool IsEnabled { get; set; } = true; } } 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 0edf72a607..3dfc61f607 100644 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/DemoAppModule.cs +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/DemoAppModule.cs @@ -1,19 +1,83 @@ -using Microsoft.Extensions.DependencyInjection; +using System.IO; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using Volo.Abp.Autofac; using Volo.Abp.BackgroundJobs.EntityFrameworkCore; +using Volo.Abp.Data; +using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore.SqlServer; using Volo.Abp.Modularity; namespace Volo.Abp.BackgroundJobs.DemoApp { [DependsOn( typeof(BackgroundJobsEntityFrameworkCoreModule), - typeof(AbpAutofacModule) + typeof(AbpAutofacModule), + typeof(AbpEntityFrameworkCoreSqlServerModule) )] public class DemoAppModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { + var configuration = BuildConfiguration(); + context.Services.AddConfiguration(configuration); + + context.Services.Configure(options => + { + options.ConnectionStrings.Default = configuration.GetConnectionString("Default"); + }); + + context.Services.Configure(options => + { + options.Configure(opts => + { + opts.UseSqlServer(); + }); + }); + + context.Services.Configure(options => + { + options.JobPollPeriod = 1000; + }); + context.Services.AddAssemblyOf(); } + + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + context + .ServiceProvider + .GetRequiredService() + .AddConsole(LogLevel.Debug); + } + + private static IConfigurationRoot BuildConfiguration(string fileName = "appsettings") + { + var fileNameWithExtension = fileName + ".json"; + var directory = Directory.GetCurrentDirectory(); + + while (!File.Exists(Path.Combine(directory, fileNameWithExtension))) + { + var parentDirectory = new DirectoryInfo(directory).Parent; + if (parentDirectory == null) + { + break; + } + + directory = parentDirectory.FullName; + } + + if(File.Exists(Path.Combine(directory, fileNameWithExtension))) + { + var builder = new ConfigurationBuilder() + .SetBasePath(directory) + .AddJsonFile(fileNameWithExtension, optional: false); + + return builder.Build(); + } + + return null; + } } } diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/SampleJobCreator.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/SampleJobCreator.cs index 9b0df9a0c2..5363101213 100644 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/SampleJobCreator.cs +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/SampleJobCreator.cs @@ -13,8 +13,10 @@ namespace Volo.Abp.BackgroundJobs.DemoApp.Jobs public void CreateJobs() { - _backgroundJobManager.Enqueue(new WriteToConsoleJobArgs { Value = "42" }); - _backgroundJobManager.Enqueue(new WriteToConsoleJobArgs { Value = "43" }); + _backgroundJobManager.Enqueue(new WriteToConsoleGreenJobArgs { Value = "test 1 (green)" }); + _backgroundJobManager.Enqueue(new WriteToConsoleGreenJobArgs { Value = "test 2 (green)" }); + _backgroundJobManager.Enqueue(new WriteToConsoleYellowJobArgs { Value = "test 1 (yellow)" }); + _backgroundJobManager.Enqueue(new WriteToConsoleYellowJobArgs { Value = "test 2 (yellow)" }); } } } diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/WriteToConsoleGreenJob.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/WriteToConsoleGreenJob.cs new file mode 100644 index 0000000000..7d2ad86372 --- /dev/null +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/WriteToConsoleGreenJob.cs @@ -0,0 +1,21 @@ +using System; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.BackgroundJobs.DemoApp.Jobs +{ + public class WriteToConsoleGreenJob : BackgroundJob, ITransientDependency + { + public override void Execute(WriteToConsoleGreenJobArgs args) + { + if (RandomHelper.GetRandomOf(1, 2) == 2) + { + throw new ApplicationException("A sample exception from the WriteToConsoleGreenJob!"); + } + + var oldColor = Console.ForegroundColor; + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine($"############### WriteToConsoleGreenJob: {args.Value} ###############"); + Console.ForegroundColor = oldColor; + } + } +} \ No newline at end of file diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/WriteToConsoleGreenJobArgs.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/WriteToConsoleGreenJobArgs.cs new file mode 100644 index 0000000000..77ec28b4f8 --- /dev/null +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/WriteToConsoleGreenJobArgs.cs @@ -0,0 +1,8 @@ +namespace Volo.Abp.BackgroundJobs.DemoApp.Jobs +{ + [BackgroundJobName("GreenJob")] + public class WriteToConsoleGreenJobArgs + { + public string Value { get; set; } + } +} \ No newline at end of file diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/WriteToConsoleJob.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/WriteToConsoleJob.cs deleted file mode 100644 index e7c5514ee8..0000000000 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/WriteToConsoleJob.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using Volo.Abp.DependencyInjection; - -namespace Volo.Abp.BackgroundJobs.DemoApp.Jobs -{ - public class WriteToConsoleJob : BackgroundJob, ITransientDependency - { - public override void Execute(WriteToConsoleJobArgs args) - { - Console.WriteLine($"WriteToConsoleJob: {args.Value}"); - } - } -} \ No newline at end of file diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/WriteToConsoleYellowJob.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/WriteToConsoleYellowJob.cs new file mode 100644 index 0000000000..514b5b3892 --- /dev/null +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/WriteToConsoleYellowJob.cs @@ -0,0 +1,21 @@ +using System; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.BackgroundJobs.DemoApp.Jobs +{ + public class WriteToConsoleYellowJob : BackgroundJob, ITransientDependency + { + public override void Execute(WriteToConsoleYellowJobArgs args) + { + if (RandomHelper.GetRandomOf(1, 2) == 2) + { + throw new ApplicationException("A sample exception from the WriteToConsoleYellowJob!"); + } + + var oldColor = Console.ForegroundColor; + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine($"############### WriteToConsoleYellowJob: {args.Value} ###############"); + Console.ForegroundColor = oldColor; + } + } +} \ No newline at end of file diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/WriteToConsoleJobArgs.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/WriteToConsoleYellowJobArgs.cs similarity index 56% rename from modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/WriteToConsoleJobArgs.cs rename to modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/WriteToConsoleYellowJobArgs.cs index f6cc94de8f..40b54c49ae 100644 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/WriteToConsoleJobArgs.cs +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Jobs/WriteToConsoleYellowJobArgs.cs @@ -1,6 +1,7 @@ namespace Volo.Abp.BackgroundJobs.DemoApp.Jobs { - public class WriteToConsoleJobArgs + [BackgroundJobName("YellowJob")] + public class WriteToConsoleYellowJobArgs { public string Value { get; set; } } diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20180724105416_BackgroundJobs_Initial.Designer.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20180724105416_BackgroundJobs_Initial.Designer.cs new file mode 100644 index 0000000000..acab1e91e7 --- /dev/null +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20180724105416_BackgroundJobs_Initial.Designer.cs @@ -0,0 +1,66 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Volo.Abp.BackgroundJobs; +using Volo.Abp.BackgroundJobs.DemoApp.Db; + +namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations +{ + [DbContext(typeof(DemoAppDbContext))] + [Migration("20180724105416_BackgroundJobs_Initial")] + partial class BackgroundJobs_Initial + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.1.0-rtm-30799") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Volo.Abp.BackgroundJobs.BackgroundJobRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CreationTime") + .HasColumnName("CreationTime"); + + b.Property("IsAbandoned") + .ValueGeneratedOnAdd() + .HasDefaultValue(false); + + b.Property("JobArgs") + .IsRequired() + .HasMaxLength(1048576); + + b.Property("JobName") + .IsRequired() + .HasMaxLength(128); + + b.Property("LastTryTime"); + + b.Property("NextTryTime"); + + b.Property("Priority") + .ValueGeneratedOnAdd() + .HasDefaultValue((byte)15); + + b.Property("TryCount") + .ValueGeneratedOnAdd() + .HasDefaultValue((short)0); + + b.HasKey("Id"); + + b.HasIndex("IsAbandoned", "NextTryTime"); + + b.ToTable("AbpBackgroundJobs"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20180724105416_BackgroundJobs_Initial.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20180724105416_BackgroundJobs_Initial.cs new file mode 100644 index 0000000000..76202a0748 --- /dev/null +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/20180724105416_BackgroundJobs_Initial.cs @@ -0,0 +1,41 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations +{ + public partial class BackgroundJobs_Initial : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AbpBackgroundJobs", + columns: table => new + { + Id = table.Column(nullable: false), + 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" }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AbpBackgroundJobs"); + } + } +} diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/DemoAppDbContextModelSnapshot.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/DemoAppDbContextModelSnapshot.cs new file mode 100644 index 0000000000..d7ca501dfb --- /dev/null +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Migrations/DemoAppDbContextModelSnapshot.cs @@ -0,0 +1,64 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Volo.Abp.BackgroundJobs; +using Volo.Abp.BackgroundJobs.DemoApp.Db; + +namespace Volo.Abp.BackgroundJobs.DemoApp.Migrations +{ + [DbContext(typeof(DemoAppDbContext))] + partial class DemoAppDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.1.0-rtm-30799") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Volo.Abp.BackgroundJobs.BackgroundJobRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CreationTime") + .HasColumnName("CreationTime"); + + b.Property("IsAbandoned") + .ValueGeneratedOnAdd() + .HasDefaultValue(false); + + b.Property("JobArgs") + .IsRequired() + .HasMaxLength(1048576); + + b.Property("JobName") + .IsRequired() + .HasMaxLength(128); + + b.Property("LastTryTime"); + + b.Property("NextTryTime"); + + b.Property("Priority") + .ValueGeneratedOnAdd() + .HasDefaultValue((byte)15); + + b.Property("TryCount") + .ValueGeneratedOnAdd() + .HasDefaultValue((short)0); + + b.HasKey("Id"); + + b.HasIndex("IsAbandoned", "NextTryTime"); + + b.ToTable("AbpBackgroundJobs"); + }); +#pragma warning restore 612, 618 + } + } +} 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 a6d4cf21c5..de863ca426 100644 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Program.cs +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Program.cs @@ -22,6 +22,8 @@ namespace Volo.Abp.BackgroundJobs.DemoApp Console.WriteLine("Press ENTER to stop the application..!"); Console.ReadLine(); + + application.Shutdown(); } } } diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Volo.Abp.BackgroundJobs.DemoApp.csproj b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Volo.Abp.BackgroundJobs.DemoApp.csproj index 06e07f2cef..028482d72c 100644 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Volo.Abp.BackgroundJobs.DemoApp.csproj +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/Volo.Abp.BackgroundJobs.DemoApp.csproj @@ -9,6 +9,8 @@ + + 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 11f6168065..0c18e9f877 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 @@ -13,9 +13,9 @@ namespace Volo.Abp.BackgroundJobs public virtual string JobName { get; set; } /// - /// Job arguments as JSON string. + /// Job arguments as serialized string. /// - public virtual string JobArgs { get; set; } //TODO: Consider to conver to byte[] + public virtual string JobArgs { get; set; } /// /// Try count of this job.