Browse Source

Merge pull request #14896 from abpframework/auto-merge/rel-7-0/1512

Merge branch dev with rel-7.0
pull/14897/head
maliming 4 years ago
committed by GitHub
parent
commit
3ff23c658b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      docs/en/Background-Workers-Hangfire.md
  2. 24
      docs/zh-Hans/Background-Workers-Hangfire.md

22
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()
@ -84,11 +77,13 @@ public class MyLogWorker : HangfireBackgroundWorkerBase, IMyLogWorker
CronExpression = Cron.Daily(); CronExpression = Cron.Daily();
} }
[UnitOfWork] public override Task DoWorkAsync(CancellationToken cancellationToken = default)
public override Task DoWorkAsync()
{ {
Logger.LogInformation("Executed MyLogWorker..!"); using (var uow = LazyServiceProvider.LazyGetRequiredService<IUnitOfWorkManager>().Begin())
return Task.CompletedTask; {
Logger.LogInformation("Executed MyLogWorker..!");
return Task.CompletedTask;
}
} }
} }
``` ```
@ -105,9 +100,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>();
} }
} }
```` ````

24
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()
@ -85,11 +78,13 @@ public class MyLogWorker : HangfireBackgroundWorkerBase, IMyLogWorker
CronExpression = Cron.Daily(); CronExpression = Cron.Daily();
} }
[UnitOfWork] public override Task DoWorkAsync(CancellationToken cancellationToken = default)
public override Task DoWorkAsync()
{ {
Logger.LogInformation("Executed MyLogWorker..!"); using (var uow = LazyServiceProvider.LazyGetRequiredService<IUnitOfWorkManager>().Begin())
return Task.CompletedTask; {
Logger.LogInformation("Executed MyLogWorker..!");
return Task.CompletedTask;
}
} }
} }
``` ```
@ -106,9 +101,6 @@ public class MyModule : AbpModule
ApplicationInitializationContext context) ApplicationInitializationContext context)
{ {
await context.AddBackgroundWorkerAsync<MyLogWorker>(); await context.AddBackgroundWorkerAsync<MyLogWorker>();
//如果定义了接口
//await context.AddBackgroundWorkerAsync<IMyLogWorker>();
} }
} }
```` ````
@ -127,4 +119,4 @@ context.ServiceProvider
它解析给定的后台工作者并添加到 `IBackgroundWorkerManager`. 它解析给定的后台工作者并添加到 `IBackgroundWorkerManager`.
虽然我们通常在 `OnApplicationInitializationAsync` 中添加后台工作者, 但对此没有限制. 你可以在任何地方注入 `IBackgroundWorkerManager` 并在运行时添加后台工作者. 虽然我们通常在 `OnApplicationInitializationAsync` 中添加后台工作者, 但对此没有限制. 你可以在任何地方注入 `IBackgroundWorkerManager` 并在运行时添加后台工作者.

Loading…
Cancel
Save