Added Volo.Abp.Hangfire project.

pull/395/head
Halil ibrahim Kalkan 7 years ago
parent d963f7cd48
commit d2dbb4035c

@ -204,6 +204,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BackgroundJobs.Abs
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BackgroundJobs.HangFire", "src\Volo.Abp.BackgroundJobs.HangFire\Volo.Abp.BackgroundJobs.HangFire.csproj", "{35AC93EF-E383-4F4E-839D-6EE1C62681F1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.HangFire", "src\Volo.Abp.HangFire\Volo.Abp.HangFire.csproj", "{EE01E964-E60E-4C3C-BCF0-AF1A0C0A3DC9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -574,6 +576,10 @@ Global
{35AC93EF-E383-4F4E-839D-6EE1C62681F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{35AC93EF-E383-4F4E-839D-6EE1C62681F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{35AC93EF-E383-4F4E-839D-6EE1C62681F1}.Release|Any CPU.Build.0 = Release|Any CPU
{EE01E964-E60E-4C3C-BCF0-AF1A0C0A3DC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE01E964-E60E-4C3C-BCF0-AF1A0C0A3DC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE01E964-E60E-4C3C-BCF0-AF1A0C0A3DC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE01E964-E60E-4C3C-BCF0-AF1A0C0A3DC9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -672,6 +678,7 @@ Global
{D86548EA-7047-4623-8824-F6285CD254AA} = {447C8A77-E5F0-4538-8687-7383196D04EA}
{EB9C3B4D-FEBD-4691-8F34-AAC2C13F6F2F} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
{35AC93EF-E383-4F4E-839D-6EE1C62681F1} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
{EE01E964-E60E-4C3C-BCF0-AF1A0C0A3DC9} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5}

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Volo.Abp.HangFire</AssemblyName>
<PackageId>Volo.Abp.HangFire</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Hangfire.AspNetCore" Version="1.6.19" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.Core\Volo.Abp.Core.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,35 @@
using Hangfire;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Volo.Abp.Modularity;
namespace Volo.Abp.Hangfire
{
public class AbpHangfireModule : AbpModule
{
private BackgroundJobServer _backgroundJobServer;
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddHangfire(configuration =>
{
context.Services.ExecutePreConfiguredActions(configuration);
});
context.Services.AddAssemblyOf<AbpHangfireModule>();
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var options = context.ServiceProvider.GetRequiredService<IOptions<AbpHangfireOptions>>().Value;
_backgroundJobServer = options.BackgroundJobServerFactory.Invoke(context.ServiceProvider);
}
public override void OnApplicationShutdown(ApplicationShutdownContext context)
{
//TODO: ABP may provide two methods for application shutdown: OnPreApplicationShutdown & OnApplicationShutdown
_backgroundJobServer.SendStop();
_backgroundJobServer.Dispose();
}
}
}

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using Hangfire;
using Hangfire.Client;
using Hangfire.Common;
using Hangfire.Server;
using Hangfire.States;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
namespace Volo.Abp.Hangfire
{
public class AbpHangfireOptions
{
[CanBeNull]
public BackgroundJobServerOptions ServerOptions { get; set; }
[CanBeNull]
public IEnumerable<IBackgroundProcess> AdditionalProcesses { get; set; }
[CanBeNull]
public JobStorage Storage { get; set; }
[NotNull]
public Func<IServiceProvider, BackgroundJobServer> BackgroundJobServerFactory
{
get => _backgroundJobServerFactory;
set => _backgroundJobServerFactory = Check.NotNull(value, nameof(value));
}
private Func<IServiceProvider, BackgroundJobServer> _backgroundJobServerFactory;
public AbpHangfireOptions()
{
_backgroundJobServerFactory = CreateJobServer;
}
private BackgroundJobServer CreateJobServer(IServiceProvider serviceProvider)
{
Storage = Storage ?? serviceProvider.GetRequiredService<JobStorage>();
ServerOptions = ServerOptions ?? serviceProvider.GetService<BackgroundJobServerOptions>() ?? new BackgroundJobServerOptions();
AdditionalProcesses = AdditionalProcesses ?? serviceProvider.GetServices<IBackgroundProcess>();
return new BackgroundJobServer(ServerOptions, Storage, AdditionalProcesses,
ServerOptions.FilterProvider ?? serviceProvider.GetRequiredService<IJobFilterProvider>(),
ServerOptions.Activator ?? serviceProvider.GetRequiredService<JobActivator>(),
serviceProvider.GetService<IBackgroundJobFactory>(),
serviceProvider.GetService<IBackgroundJobPerformer>(),
serviceProvider.GetService<IBackgroundJobStateChanger>()
);
}
}
}

@ -25,7 +25,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.BackgroundJobs.Ent
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.BackgroundJobs.MongoDB.Tests", "test\Volo.Abp.BackgroundJobs.MongoDB.Tests\Volo.Abp.BackgroundJobs.MongoDB.Tests.csproj", "{AA783A34-86E4-41A5-AE21-5D9FBD98D858}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BackgroundJobs.DemoApp", "app\Volo.Abp.BackgroundJobs.DemoApp\Volo.Abp.BackgroundJobs.DemoApp.csproj", "{9A871D66-BE8D-440C-BF79-F778F8A50BF3}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.BackgroundJobs.DemoApp", "app\Volo.Abp.BackgroundJobs.DemoApp\Volo.Abp.BackgroundJobs.DemoApp.csproj", "{9A871D66-BE8D-440C-BF79-F778F8A50BF3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BackgroundJobs.DemoApp.Shared", "app\Volo.Abp.BackgroundJobs.DemoApp.Shared\Volo.Abp.BackgroundJobs.DemoApp.Shared.csproj", "{DE6914FF-F60A-461A-8498-461198E917BE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BackgroundJobs.DemoApp.HangFire", "app\Volo.Abp.BackgroundJobs.DemoApp.HangFire\Volo.Abp.BackgroundJobs.DemoApp.HangFire.csproj", "{2060AC85-2598-4342-A87C-A684A2C71A37}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -69,6 +73,14 @@ Global
{9A871D66-BE8D-440C-BF79-F778F8A50BF3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A871D66-BE8D-440C-BF79-F778F8A50BF3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A871D66-BE8D-440C-BF79-F778F8A50BF3}.Release|Any CPU.Build.0 = Release|Any CPU
{DE6914FF-F60A-461A-8498-461198E917BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DE6914FF-F60A-461A-8498-461198E917BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE6914FF-F60A-461A-8498-461198E917BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE6914FF-F60A-461A-8498-461198E917BE}.Release|Any CPU.Build.0 = Release|Any CPU
{2060AC85-2598-4342-A87C-A684A2C71A37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2060AC85-2598-4342-A87C-A684A2C71A37}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2060AC85-2598-4342-A87C-A684A2C71A37}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2060AC85-2598-4342-A87C-A684A2C71A37}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -83,6 +95,8 @@ Global
{E5906DE1-B2F5-472E-BE1B-1D96A68B834D} = {CCD2960C-23CC-4AB4-B84D-60C7AAA52F4D}
{AA783A34-86E4-41A5-AE21-5D9FBD98D858} = {CCD2960C-23CC-4AB4-B84D-60C7AAA52F4D}
{9A871D66-BE8D-440C-BF79-F778F8A50BF3} = {E400416D-2895-4512-9D17-90681EEC7E0A}
{DE6914FF-F60A-461A-8498-461198E917BE} = {E400416D-2895-4512-9D17-90681EEC7E0A}
{2060AC85-2598-4342-A87C-A684A2C71A37} = {E400416D-2895-4512-9D17-90681EEC7E0A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4324B3B4-B60B-4E3C-91D8-59576B4E26DD}

@ -0,0 +1,43 @@
using Hangfire;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Autofac;
using Volo.Abp.BackgroundJobs.DemoApp.Shared;
using Volo.Abp.Hangfire;
using Volo.Abp.Modularity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace Volo.Abp.BackgroundJobs.DemoApp.HangFire
{
[DependsOn(
typeof(DemoAppSharedModule),
typeof(AbpAutofacModule),
typeof(AbpHangfireModule)
)]
public class DemoAppHangfireModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
var configuration = ConfigurationHelper.BuildConfiguration();
context.Services.AddConfiguration(configuration);
context.Services.PreConfigure<IGlobalConfiguration>(hangfireConfiguration =>
{
hangfireConfiguration.UseSqlServerStorage(configuration.GetConnectionString("Default"));
});
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAssemblyOf<DemoAppHangfireModule>();
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
context
.ServiceProvider
.GetRequiredService<ILoggerFactory>()
.AddConsole(LogLevel.Debug);
}
}
}

@ -0,0 +1,24 @@
using System;
namespace Volo.Abp.BackgroundJobs.DemoApp.HangFire
{
class Program
{
static void Main(string[] args)
{
using (var application = AbpApplicationFactory.Create<DemoAppHangfireModule>(options =>
{
options.UseAutofac();
}))
{
application.Initialize();
Console.WriteLine("Started: " + typeof(Program).Namespace);
Console.WriteLine("Press ENTER to stop the application..!");
Console.ReadLine();
application.Shutdown();
}
}
}
}

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Hangfire.SqlServer" Version="1.6.19" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.HangFire\Volo.Abp.HangFire.csproj" />
<ProjectReference Include="..\Volo.Abp.BackgroundJobs.DemoApp.Shared\Volo.Abp.BackgroundJobs.DemoApp.Shared.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,37 @@
using System.IO;
using Microsoft.Extensions.Configuration;
namespace Volo.Abp.BackgroundJobs.DemoApp.Shared
{
public static class ConfigurationHelper
{
public static IConfigurationRoot BuildConfiguration()
{
const string fileName = "appsettings.json";
var directory = Directory.GetCurrentDirectory();
while (!File.Exists(Path.Combine(directory, fileName)))
{
var parentDirectory = new DirectoryInfo(directory).Parent;
if (parentDirectory == null)
{
break;
}
directory = parentDirectory.FullName;
}
if (File.Exists(Path.Combine(directory, fileName)))
{
var builder = new ConfigurationBuilder()
.SetBasePath(directory)
.AddJsonFile(fileName, optional: false);
return builder.Build();
}
return null;
}
}
}

@ -0,0 +1,24 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.BackgroundJobs.DemoApp.Shared.Jobs;
using Volo.Abp.Modularity;
namespace Volo.Abp.BackgroundJobs.DemoApp.Shared
{
[DependsOn(
typeof(AbpBackgroundJobsAbstractionsModule)
)]
public class DemoAppSharedModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAssemblyOf<DemoAppSharedModule>();
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
context.ServiceProvider
.GetRequiredService<SampleJobCreator>()
.CreateJobs();
}
}
}

@ -1,6 +1,6 @@
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.BackgroundJobs.DemoApp.Jobs
namespace Volo.Abp.BackgroundJobs.DemoApp.Shared.Jobs
{
public class SampleJobCreator : ITransientDependency
{

@ -1,13 +1,13 @@
using System;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.BackgroundJobs.DemoApp.Jobs
namespace Volo.Abp.BackgroundJobs.DemoApp.Shared.Jobs
{
public class WriteToConsoleGreenJob : BackgroundJob<WriteToConsoleGreenJobArgs>, ITransientDependency
{
public override void Execute(WriteToConsoleGreenJobArgs args)
{
if (RandomHelper.GetRandom(0,100) < 70)
if (RandomHelper.GetRandom(0, 100) < 70)
{
throw new ApplicationException("A sample exception from the WriteToConsoleGreenJob!");
}

@ -1,4 +1,4 @@
namespace Volo.Abp.BackgroundJobs.DemoApp.Jobs
namespace Volo.Abp.BackgroundJobs.DemoApp.Shared.Jobs
{
[BackgroundJobName("GreenJob")]
public class WriteToConsoleGreenJobArgs

@ -1,7 +1,7 @@
using System;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.BackgroundJobs.DemoApp.Jobs
namespace Volo.Abp.BackgroundJobs.DemoApp.Shared.Jobs
{
public class WriteToConsoleYellowJob : BackgroundJob<WriteToConsoleYellowJobArgs>, ITransientDependency
{

@ -1,4 +1,4 @@
namespace Volo.Abp.BackgroundJobs.DemoApp.Jobs
namespace Volo.Abp.BackgroundJobs.DemoApp.Shared.Jobs
{
[BackgroundJobName("YellowJob")]
public class WriteToConsoleYellowJobArgs

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.0" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.BackgroundJobs.Abstractions\Volo.Abp.BackgroundJobs.Abstractions.csproj" />
</ItemGroup>
</Project>

@ -1,8 +1,8 @@
using System.IO;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Volo.Abp.Autofac;
using Volo.Abp.BackgroundJobs.DemoApp.Shared;
using Volo.Abp.BackgroundJobs.EntityFrameworkCore;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
@ -12,6 +12,7 @@ using Volo.Abp.Modularity;
namespace Volo.Abp.BackgroundJobs.DemoApp
{
[DependsOn(
typeof(DemoAppSharedModule),
typeof(BackgroundJobsEntityFrameworkCoreModule),
typeof(AbpAutofacModule),
typeof(AbpEntityFrameworkCoreSqlServerModule)
@ -20,7 +21,8 @@ namespace Volo.Abp.BackgroundJobs.DemoApp
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = BuildConfiguration();
var configuration = ConfigurationHelper.BuildConfiguration();
context.Services.AddConfiguration(configuration);
context.Services.Configure<DbConnectionOptions>(options =>
@ -54,33 +56,5 @@ namespace Volo.Abp.BackgroundJobs.DemoApp
.GetRequiredService<ILoggerFactory>()
.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;
}
}
}

@ -1,6 +1,4 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.BackgroundJobs.DemoApp.Jobs;
namespace Volo.Abp.BackgroundJobs.DemoApp
{
@ -15,11 +13,7 @@ namespace Volo.Abp.BackgroundJobs.DemoApp
{
application.Initialize();
application
.ServiceProvider
.GetRequiredService<SampleJobCreator>()
.CreateJobs();
Console.WriteLine("Started: " + typeof(Program).Namespace);
Console.WriteLine("Press ENTER to stop the application..!");
Console.ReadLine();

@ -6,14 +6,12 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.0" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp.BackgroundJobs.EntityFrameworkCore\Volo.Abp.BackgroundJobs.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.EntityFrameworkCore.SqlServer\Volo.Abp.EntityFrameworkCore.SqlServer.csproj" />
<ProjectReference Include="..\Volo.Abp.BackgroundJobs.DemoApp.Shared\Volo.Abp.BackgroundJobs.DemoApp.Shared.csproj" />
</ItemGroup>
</Project>

Loading…
Cancel
Save