Browse Source
Merge pull request #622 from colinin/5.3.0
fix: Tenant needs to be specified to execute job events
pull/645/head
yx lin
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
72 additions and
74 deletions
-
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobEventBase.cs
-
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/JobExecutedEvent.cs
-
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/JobLogEvent.cs
|
|
|
@ -1,7 +1,9 @@ |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Microsoft.Extensions.Logging.Abstractions; |
|
|
|
using System; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.MultiTenancy; |
|
|
|
|
|
|
|
namespace LINGYUN.Abp.BackgroundTasks; |
|
|
|
|
|
|
|
@ -16,9 +18,13 @@ public abstract class JobEventBase<TEvent> : IJobEvent |
|
|
|
public async Task OnJobAfterExecuted(JobEventContext context) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
var currentTenant = context.ServiceProvider.GetRequiredService<ICurrentTenant>(); |
|
|
|
using (currentTenant.Change(context.EventData.TenantId)) |
|
|
|
{ |
|
|
|
await OnJobAfterExecutedAsync(context); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
Logger.LogError("Failed to execute event, error:" + GetSourceException(ex).Message); |
|
|
|
@ -28,9 +34,13 @@ public abstract class JobEventBase<TEvent> : IJobEvent |
|
|
|
public async Task OnJobBeforeExecuted(JobEventContext context) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
var currentTenant = context.ServiceProvider.GetRequiredService<ICurrentTenant>(); |
|
|
|
using (currentTenant.Change(context.EventData.TenantId)) |
|
|
|
{ |
|
|
|
await OnJobBeforeExecutedAsync(context); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
Logger.LogError("Failed to execute preprocessing event, error:" + GetSourceException(ex).Message); |
|
|
|
|
|
|
|
@ -2,7 +2,6 @@ |
|
|
|
using System; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
using Volo.Abp.MultiTenancy; |
|
|
|
|
|
|
|
namespace LINGYUN.Abp.BackgroundTasks.Internal; |
|
|
|
|
|
|
|
@ -11,10 +10,6 @@ public class JobExecutedEvent : JobEventBase<JobExecutedEvent>, ITransientDepend |
|
|
|
protected override async Task OnJobAfterExecutedAsync(JobEventContext context) |
|
|
|
{ |
|
|
|
var store = context.ServiceProvider.GetRequiredService<IJobStore>(); |
|
|
|
var currentTenant = context.ServiceProvider.GetRequiredService<ICurrentTenant>(); |
|
|
|
|
|
|
|
using (currentTenant.Change(context.EventData.TenantId)) |
|
|
|
{ |
|
|
|
var job = await store.FindAsync(context.EventData.Key); |
|
|
|
if (job != null) |
|
|
|
{ |
|
|
|
@ -91,7 +86,6 @@ public class JobExecutedEvent : JobEventBase<JobExecutedEvent>, ITransientDepend |
|
|
|
await store.StoreAsync(job); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private async Task RemoveJobAsync(JobEventContext context, JobInfo jobInfo) |
|
|
|
{ |
|
|
|
|
|
|
|
@ -2,7 +2,6 @@ |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.Auditing; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
using Volo.Abp.MultiTenancy; |
|
|
|
|
|
|
|
namespace LINGYUN.Abp.BackgroundTasks.Internal; |
|
|
|
|
|
|
|
@ -21,11 +20,6 @@ public class JobLogEvent : JobEventBase<JobLogEvent>, ITransientDependency |
|
|
|
return; |
|
|
|
} |
|
|
|
var store = context.ServiceProvider.GetRequiredService<IJobStore>(); |
|
|
|
var currentTenant = context.ServiceProvider.GetRequiredService<ICurrentTenant>(); |
|
|
|
|
|
|
|
using (currentTenant.Change(context.EventData.TenantId)) |
|
|
|
{ |
|
|
|
await store.StoreLogAsync(context.EventData); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|