Browse Source

Update Hangfire document

pull/14895/head
liangshiwei 4 years ago
parent
commit
17f345c5a7
  1. 21
      docs/en/Background-Workers-Hangfire.md
  2. 21
      docs/zh-Hans/Background-Workers-Hangfire.md

21
docs/en/Background-Workers-Hangfire.md

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

21
docs/zh-Hans/Background-Workers-Hangfire.md

@ -54,7 +54,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;
@ -69,14 +69,7 @@ public class MyLogWorker : HangfireBackgroundWorkerBase
### UnitOfWork ### UnitOfWork
使用 `UnitOfWorkAttribute` 你需要为工作者定义一个接口:
```csharp ```csharp
public interface IMyLogWorker : IHangfireBackgroundWorker
{
}
[ExposeServices(typeof(IMyLogWorker))]
public class MyLogWorker : HangfireBackgroundWorkerBase, IMyLogWorker public class MyLogWorker : HangfireBackgroundWorkerBase, IMyLogWorker
{ {
public MyLogWorker() public MyLogWorker()
@ -86,10 +79,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;
}
} }
} }
``` ```
@ -106,9 +102,6 @@ public class MyModule : AbpModule
ApplicationInitializationContext context) ApplicationInitializationContext context)
{ {
await context.AddBackgroundWorkerAsync<MyLogWorker>(); await context.AddBackgroundWorkerAsync<MyLogWorker>();
//如果定义了接口
//await context.AddBackgroundWorkerAsync<IMyLogWorker>();
} }
} }
```` ````

Loading…
Cancel
Save