Browse Source

fix: Tenant needs to be specified to execute job events

pull/622/head
cKey 4 years ago
parent
commit
79808f35b1
  1. 12
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobEventBase.cs
  2. 6
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/JobExecutedEvent.cs
  3. 6
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/JobLogEvent.cs

12
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobEventBase.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);

6
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/JobExecutedEvent.cs

@ -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)
{

6
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/JobLogEvent.cs

@ -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);
}
}
}

Loading…
Cancel
Save