mirror of https://github.com/abpframework/abp.git
22 changed files with 201 additions and 145 deletions
@ -1,38 +0,0 @@ |
|||
using System; |
|||
using System.Runtime.Serialization; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs |
|||
{ |
|||
[Serializable] |
|||
public class BackgroundJobException : AbpException |
|||
{ |
|||
public string JobName { get; set; } |
|||
|
|||
public string JobArgs { get; set; } |
|||
|
|||
public BackgroundJobException() |
|||
{ |
|||
|
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Creates a new <see cref="BackgroundJobException"/> object.
|
|||
/// </summary>
|
|||
public BackgroundJobException(SerializationInfo serializationInfo, StreamingContext context) |
|||
: base(serializationInfo, context) |
|||
{ |
|||
|
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Creates a new <see cref="BackgroundJobException"/> object.
|
|||
/// </summary>
|
|||
/// <param name="message">Exception message</param>
|
|||
/// <param name="innerException">Inner exception</param>
|
|||
public BackgroundJobException(string message, Exception innerException) |
|||
: base(message, innerException) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
using System; |
|||
using System.Runtime.Serialization; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs |
|||
{ |
|||
[Serializable] |
|||
public class BackgroundJobExecutionException : AbpException |
|||
{ |
|||
public string JobType { get; set; } |
|||
|
|||
public object JobArgs { get; set; } |
|||
|
|||
public BackgroundJobExecutionException() |
|||
{ |
|||
|
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Creates a new <see cref="BackgroundJobExecutionException"/> object.
|
|||
/// </summary>
|
|||
public BackgroundJobExecutionException(SerializationInfo serializationInfo, StreamingContext context) |
|||
: base(serializationInfo, context) |
|||
{ |
|||
|
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Creates a new <see cref="BackgroundJobExecutionException"/> object.
|
|||
/// </summary>
|
|||
/// <param name="message">Exception message</param>
|
|||
/// <param name="innerException">Inner exception</param>
|
|||
public BackgroundJobExecutionException(string message, Exception innerException) |
|||
: base(message, innerException) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -1,11 +1,21 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<AssemblyName>Volo.Abp.BackgroundJobs.HangFire</AssemblyName> |
|||
<PackageId>Volo.Abp.BackgroundJobs.HangFire</PackageId> |
|||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Volo.Abp.BackgroundJobs.Abstractions\Volo.Abp.BackgroundJobs.Abstractions.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.HangFire\Volo.Abp.HangFire.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
|
|||
@ -1,15 +0,0 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.HangFire.Volo.Abp.BackgroundJobs.Hangfire |
|||
{ |
|||
public class BackgroundJobManager : IBackgroundJobManager, ITransientDependency |
|||
{ |
|||
public Task<Guid> EnqueueAsync<TArgs>(TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, |
|||
TimeSpan? delay = null) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Hangfire; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.Hangfire |
|||
{ |
|||
public class HangfireBackgroundJobManager : IBackgroundJobManager, ITransientDependency |
|||
{ |
|||
public Task<string> EnqueueAsync<TArgs>(TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, |
|||
TimeSpan? delay = null) |
|||
{ |
|||
if (!delay.HasValue) |
|||
{ |
|||
return Task.FromResult(BackgroundJob.Enqueue<HangfireJobExecutionAdapter<TArgs>>(adapter => adapter.Execute(args))); |
|||
} |
|||
else |
|||
{ |
|||
return Task.FromResult(BackgroundJob.Schedule<HangfireJobExecutionAdapter<TArgs>>(adapter => adapter.Execute(args), delay.Value)); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
using Microsoft.Extensions.Options; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.Hangfire |
|||
{ |
|||
public class HangfireJobExecutionAdapter<TArgs> |
|||
{ |
|||
protected BackgroundJobOptions Options { get; } |
|||
protected IBackgroundJobExecuter JobExecuter { get; } |
|||
|
|||
public HangfireJobExecutionAdapter(IOptions<BackgroundJobOptions> options, IBackgroundJobExecuter jobExecuter) |
|||
{ |
|||
JobExecuter = jobExecuter; |
|||
Options = options.Value; |
|||
} |
|||
|
|||
public void Execute(TArgs args) |
|||
{ |
|||
var jobName = BackgroundJobNameAttribute.GetName<TArgs>(); |
|||
var jobType = Options.GetJobType(jobName); |
|||
|
|||
var context = new JobExecutionContext(jobType, args); |
|||
JobExecuter.Execute(context); |
|||
if (context.Result == JobExecutionResult.Failed) |
|||
{ |
|||
throw new AbpException("Job failed"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,5 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;Trusted_Connection=True;MultipleActiveResultSets=true" |
|||
} |
|||
} |
|||
Loading…
Reference in new issue