|
|
@ -53,7 +53,7 @@ public class MyLogWorker : HangfireBackgroundWorkerBase |
|
|
CronExpression = Cron.Daily(); |
|
|
CronExpression = Cron.Daily(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public override Task DoWorkAsync() |
|
|
public override Task DoWorkAsync(CancellationToken cancellationToken = default) |
|
|
{ |
|
|
{ |
|
|
Logger.LogInformation("Executed MyLogWorker..!"); |
|
|
Logger.LogInformation("Executed MyLogWorker..!"); |
|
|
return Task.CompletedTask; |
|
|
return Task.CompletedTask; |
|
|
@ -68,14 +68,7 @@ public class MyLogWorker : HangfireBackgroundWorkerBase |
|
|
|
|
|
|
|
|
### UnitOfWork |
|
|
### UnitOfWork |
|
|
|
|
|
|
|
|
For use with `UnitOfWorkAttribute`, you need to define an interface for worker: |
|
|
|
|
|
|
|
|
|
|
|
```csharp |
|
|
```csharp |
|
|
public interface IMyLogWorker : IHangfireBackgroundWorker |
|
|
|
|
|
{ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[ExposeServices(typeof(IMyLogWorker))] |
|
|
|
|
|
public class MyLogWorker : HangfireBackgroundWorkerBase, IMyLogWorker |
|
|
public class MyLogWorker : HangfireBackgroundWorkerBase, IMyLogWorker |
|
|
{ |
|
|
{ |
|
|
public MyLogWorker() |
|
|
public MyLogWorker() |
|
|
@ -85,10 +78,13 @@ public class MyLogWorker : HangfireBackgroundWorkerBase, IMyLogWorker |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[UnitOfWork] |
|
|
[UnitOfWork] |
|
|
public override Task DoWorkAsync() |
|
|
public override Task DoWorkAsync(CancellationToken cancellationToken = default) |
|
|
{ |
|
|
{ |
|
|
Logger.LogInformation("Executed MyLogWorker..!"); |
|
|
using (var uow = LazyServiceProvider.LazyGetRequiredService<IUnitOfWorkManager>().Begin()) |
|
|
return Task.CompletedTask; |
|
|
{ |
|
|
|
|
|
Logger.LogInformation("Executed MyLogWorker..!"); |
|
|
|
|
|
return Task.CompletedTask; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
``` |
|
|
``` |
|
|
@ -105,9 +101,6 @@ public class MyModule : AbpModule |
|
|
ApplicationInitializationContext context) |
|
|
ApplicationInitializationContext context) |
|
|
{ |
|
|
{ |
|
|
await context.AddBackgroundWorkerAsync<MyLogWorker>(); |
|
|
await context.AddBackgroundWorkerAsync<MyLogWorker>(); |
|
|
|
|
|
|
|
|
//If the interface is defined |
|
|
|
|
|
//await context.AddBackgroundWorkerAsync<IMyLogWorker>(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
```` |
|
|
```` |
|
|
|