-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from marcwittke/release/3.0.1
Release/3.0.1
- Loading branch information
Showing
41 changed files
with
475 additions
and
252 deletions.
There are no files selected for viewing
35 changes: 29 additions & 6 deletions
35
demo/DemoBlog.Application/Application/Jobs/ApplicationRuntimeJobWrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,49 @@ | ||
namespace DemoBlog.Bootstrapping.Jobs | ||
namespace DemoBlog.Application.Jobs | ||
{ | ||
using System; | ||
using Backend.Fx.Environment.Authentication; | ||
using Backend.Fx.Environment.MultiTenancy; | ||
using Backend.Fx.Patterns.DependencyInjection; | ||
using Backend.Fx.Patterns.Jobs; | ||
using JetBrains.Annotations; | ||
|
||
/// <summary> | ||
/// Wraps a pure Application Job (implementing <see cref="FluentScheduler.IJob"/>) in a | ||
/// Fluent Scheduler Job (implementing <see cref="FluentScheduler.IJob"/>) to make it schedulable | ||
/// </summary> | ||
public class ApplicationRuntimeJobWrapper<TApplicationJob> : FluentScheduler.IJob where TApplicationJob : class, Backend.Fx.Patterns.Jobs.IJob | ||
public class ApplicationRuntimeJobWrapper : FluentScheduler.IJob | ||
{ | ||
private readonly IJobExecutor jobExecutor; | ||
private readonly IScopeManager scopeManager; | ||
private readonly ITenantManager tenantManager; | ||
private readonly Type jobType; | ||
|
||
[UsedImplicitly] | ||
public ApplicationRuntimeJobWrapper(IJobExecutor jobExecutor) | ||
public ApplicationRuntimeJobWrapper(IScopeManager scopeManager, ITenantManager tenantManager, Type jobType) | ||
{ | ||
this.jobExecutor = jobExecutor; | ||
this.scopeManager = scopeManager; | ||
this.tenantManager = tenantManager; | ||
this.jobType = jobType; | ||
} | ||
|
||
[UsedImplicitly] | ||
public void Execute() | ||
{ | ||
jobExecutor.ExecuteJobAsync<TApplicationJob>().RunSynchronously(); | ||
foreach (var tenantId in tenantManager.GetTenantIds()) | ||
{ | ||
using (var scope = scopeManager.BeginScope(new SystemIdentity(), tenantId)) | ||
{ | ||
var jobExecutorType = typeof(IJobExecutor<>).MakeGenericType(jobType); | ||
IJobExecutor jobExecutor = (IJobExecutor) scope.GetInstance(jobExecutorType); | ||
jobExecutor.ExecuteJob(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public class ApplicationRuntimeJobWrapper<TJob> : ApplicationRuntimeJobWrapper | ||
{ | ||
public ApplicationRuntimeJobWrapper(IScopeManager scopeManager, ITenantManager tenantManager) | ||
: base(scopeManager, tenantManager, typeof(TJob)) | ||
{ } | ||
} | ||
} |
23 changes: 13 additions & 10 deletions
23
...tion/Jobs/ApplicationRuntimeJobFactory.cs → ...ication/Jobs/CompositionRootJobFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,40 @@ | ||
namespace DemoBlog.Bootstrapping.Jobs | ||
namespace DemoBlog.Application.Jobs | ||
{ | ||
using System; | ||
using Backend.Fx.Environment.MultiTenancy; | ||
using Backend.Fx.Logging; | ||
using Backend.Fx.Patterns.Jobs; | ||
using Backend.Fx.Patterns.DependencyInjection; | ||
using FluentScheduler; | ||
using IJob = FluentScheduler.IJob; | ||
|
||
/// <summary> | ||
/// Factory to enable FluentScheduler to use our application runtime | ||
/// </summary> | ||
public class ApplicationRuntimeJobFactory : IJobFactory | ||
{ | ||
private static readonly ILogger Logger = LogManager.Create<ApplicationRuntimeJobFactory>(); | ||
private readonly IJobExecutor jobExecutor; | ||
|
||
public ApplicationRuntimeJobFactory(IJobExecutor jobExecutor) | ||
private readonly IScopeManager scopeManager; | ||
private readonly ITenantManager tenantManager; | ||
|
||
public ApplicationRuntimeJobFactory(IScopeManager scopeManager, ITenantManager tenantManager) | ||
{ | ||
this.jobExecutor = jobExecutor; | ||
this.scopeManager = scopeManager; | ||
this.tenantManager = tenantManager; | ||
} | ||
|
||
public IJob GetJobInstance<T>() where T : IJob | ||
{ | ||
object jobInstance; | ||
try | ||
{ | ||
jobInstance = Activator.CreateInstance(typeof(T), jobExecutor); | ||
IJob job = (IJob) Activator.CreateInstance(typeof(T), scopeManager, tenantManager); | ||
return job; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Logger.Error(ex, $"Unable to create an instance of {typeof(T).Name}. Are you sure it implements ApplicationRuntimeJobWrapper<T>?"); | ||
throw; | ||
} | ||
return (IJob)jobInstance; | ||
|
||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Backend.Fx.AspNetCore/ProgramBase.cs → ...Backend.Fx.AspNetCore/BackendFxProgram.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace Backend.Fx.AspNetCore.Integration | ||
namespace Backend.Fx.AspNetCore | ||
{ | ||
using System; | ||
using Logging; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/Backend.Fx.AspNetCore/ErrorHandling/ExceptionLoggingFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace Backend.Fx.AspNetCore.ErrorHandling | ||
{ | ||
using Logging; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
|
||
public class ExceptionLoggingFilter : IActionFilter | ||
{ | ||
public void OnActionExecuting(ActionExecutingContext context) | ||
{ } | ||
|
||
public void OnActionExecuted(ActionExecutedContext context) | ||
{ | ||
if (context.Exception != null && !context.HttpContext.Items.ContainsKey("ExceptionLogged")) | ||
{ | ||
ILogger logger = LogManager.Create(context.Controller.GetType().FullName); | ||
IExceptionLogger exceptionLogger = new ExceptionLogger(logger); | ||
exceptionLogger.LogException(context.Exception); | ||
context.HttpContext.Items["ExceptionLogged"] = true; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.