From 798da7473c264c28b6b15026fe2dca8a39406898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C3=87otur?= Date: Wed, 4 Mar 2020 15:54:30 +0300 Subject: [PATCH 1/9] Create Background-Workers.md --- docs/en/Background-Workers.md | 83 +++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 docs/en/Background-Workers.md diff --git a/docs/en/Background-Workers.md b/docs/en/Background-Workers.md new file mode 100644 index 0000000000..22e7c66e4d --- /dev/null +++ b/docs/en/Background-Workers.md @@ -0,0 +1,83 @@ +# Background Workers + +## Introduction + +Background workers are used to execute some tasks in the background. You may need background workers for several reasons. + +### Create a Background Worker + +A background worker is a class that derives from the `AsyncPeriodicBackgroundWorkerBase` or `PeriodicBackgroundWorkerBase` class. Both base classes are derived from `ISingletonDependency`. + +### Status Checker +This example is used to simple check remote application status. Just suppose that, we want to check and store some web applications are running or not? + +````csharp +public class AppStatusService : ITransientDependency +{ + . + . + public void CheckAppStatus() + { + var ping = new System.Net.NetworkInformation.Ping(); + + var result = ping.Send("www.google.com"); + + // save the result + } + . + . +} +```` + +Then create a background worker class that derived from the `PeriodicBackgroundWorkerBase`: + +````csharp +. +. +using Volo.Abp.BackgroundWorkers; + +namespace Volo.Www.Application +{ + public class AppStatusCheckingWorker : PeriodicBackgroundWorkerBase + { + private readonly IAppStatusService _appStatusService; + + public AppStatusCheckingWorker( + AbpTimer timer, + IServiceScopeFactory scopeFactory, + IAppStatusService appStatusService) + : base(timer, scopeFactory) + { + _appStatusService = appStatusService; + Timer.Period = 10_000; // 10 secs + } + + protected override void DoWork(PeriodicBackgroundWorkerContext workerContext) + { + _appStatusService.CheckAppStatus(); + } + } +} +```` + +This worker will call DoWorkAsync() method every 10 seconds while the application is running. + +### Configuration + +Add your BackgroundWorker at `OnApplicationInitialization` in your [module class](Module-Development-Basics.md). The example below initialize the background worker to your module: + +````csharp +using Volo.Abp.BackgroundWorkers; + +public class MyModule : AbpModule +{ + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + context.ServiceProvider + .GetRequiredService() + .Add( + context.ServiceProvider.GetRequiredService() + ); + } +} +```` \ No newline at end of file From 6d1e72f4846197ad138b288f6ef58911c1948421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C3=87otur?= Date: Wed, 4 Mar 2020 15:56:16 +0300 Subject: [PATCH 2/9] Update Background-Workers.md --- docs/en/Background-Workers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/Background-Workers.md b/docs/en/Background-Workers.md index 22e7c66e4d..7c0e58b501 100644 --- a/docs/en/Background-Workers.md +++ b/docs/en/Background-Workers.md @@ -2,7 +2,7 @@ ## Introduction -Background workers are used to execute some tasks in the background. You may need background workers for several reasons. +Background workers are used to execute some tasks in the background periodically. ### Create a Background Worker From 13628e20ba6e54463c8a02cc058b41af366d7eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C3=87otur?= Date: Wed, 4 Mar 2020 15:56:38 +0300 Subject: [PATCH 3/9] Update Background-Workers.md --- docs/en/Background-Workers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/Background-Workers.md b/docs/en/Background-Workers.md index 7c0e58b501..10dc18745a 100644 --- a/docs/en/Background-Workers.md +++ b/docs/en/Background-Workers.md @@ -20,7 +20,7 @@ public class AppStatusService : ITransientDependency { var ping = new System.Net.NetworkInformation.Ping(); - var result = ping.Send("www.google.com"); + var result = ping.Send("www.github.com"); // save the result } From cfa735d9ddf6592ded63174f03ea5b661ba2e9f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C3=87otur?= Date: Fri, 6 Mar 2020 16:37:30 +0300 Subject: [PATCH 4/9] background workers documentation added --- docs/en/Background-Jobs.md | 5 +- docs/en/Background-Workers.md | 90 ++++++++++++++++------------------- 2 files changed, 45 insertions(+), 50 deletions(-) diff --git a/docs/en/Background-Jobs.md b/docs/en/Background-Jobs.md index 70f06bbadb..b5dce34ddf 100644 --- a/docs/en/Background-Jobs.md +++ b/docs/en/Background-Jobs.md @@ -171,4 +171,7 @@ Background job system is extensible and you can change the default background jo See pre-built job manager alternatives: * [Hangfire Background Job Manager](Background-Jobs-Hangfire.md) -* [RabbitMQ Background Job Manager](Background-Jobs-RabbitMq.md) \ No newline at end of file +* [RabbitMQ Background Job Manager](Background-Jobs-RabbitMq.md) + +## See More +* [Background Workers](Background-Workers.md) \ No newline at end of file diff --git a/docs/en/Background-Workers.md b/docs/en/Background-Workers.md index 10dc18745a..4f7faffc71 100644 --- a/docs/en/Background-Workers.md +++ b/docs/en/Background-Workers.md @@ -2,73 +2,56 @@ ## Introduction -Background workers are used to execute some tasks in the background periodically. +Background workers are different than [background jobs](Background-Jobs.md). They are simple independent threads in the application running in the background. Generally, they run periodically to perform some tasks. Examples; + +* A background worker can run periodically to delete old logs. +* A background worker can run periodically to determine inactive users and send emails to get users to return to your application. + ### Create a Background Worker -A background worker is a class that derives from the `AsyncPeriodicBackgroundWorkerBase` or `PeriodicBackgroundWorkerBase` class. Both base classes are derived from `ISingletonDependency`. +A background worker is a `Singleton Depency` class that derives from the `AsyncPeriodicBackgroundWorkerBase` or `PeriodicBackgroundWorkerBase`. -### Status Checker -This example is used to simple check remote application status. Just suppose that, we want to check and store some web applications are running or not? +Assume that we want to make a user passive, if he did not login to the application in last 30 days. See the code: ````csharp -public class AppStatusService : ITransientDependency +public class PassiveUserCheckerWorker : AsyncPeriodicBackgroundWorkerBase { - . - . - public void CheckAppStatus() + private readonly IUserRepository _userRepository; + private readonly ILogger _logger; + + public PassiveUserCheckerWorker( + AbpTimer timer, + IServiceScopeFactory serviceScopeFactory, + IUserRepository userRepository, + ILogger logger + ) : base(timer, serviceScopeFactory) { - var ping = new System.Net.NetworkInformation.Ping(); - - var result = ping.Send("www.github.com"); - - // save the result + _userRepository = userRepository; + _logger = logger; + Timer.Period = 5_000; //5 seconds (good for tests) } - . - . -} -```` -Then create a background worker class that derived from the `PeriodicBackgroundWorkerBase`: - -````csharp -. -. -using Volo.Abp.BackgroundWorkers; - -namespace Volo.Www.Application -{ - public class AppStatusCheckingWorker : PeriodicBackgroundWorkerBase + protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext) { - private readonly IAppStatusService _appStatusService; + _logger.LogInformation($"{nameof(PassiveUserCheckerWorker)} started to work."); + + // UserRepository sets statuses of inactive users as a passive. + await _userRepository.UpdateInactiveUserStatusesAsync(); - public AppStatusCheckingWorker( - AbpTimer timer, - IServiceScopeFactory scopeFactory, - IAppStatusService appStatusService) - : base(timer, scopeFactory) - { - _appStatusService = appStatusService; - Timer.Period = 10_000; // 10 secs - } - - protected override void DoWork(PeriodicBackgroundWorkerContext workerContext) - { - _appStatusService.CheckAppStatus(); - } + _logger.LogInformation($"{nameof(PassiveUserCheckerWorker)} finished it's work."); } } ```` -This worker will call DoWorkAsync() method every 10 seconds while the application is running. +* If your background worker derive from `PeriodicBackgroundWorkerBase`, you should implement the `DoWork` method to perform your periodic working code. +* If you directly implement IBackgroundWorker, you will override/implement the Start and Stop methods. -### Configuration +### Register Background Worker -Add your BackgroundWorker at `OnApplicationInitialization` in your [module class](Module-Development-Basics.md). The example below initialize the background worker to your module: +After creating a background worker, add it to the IBackgroundWorkerManager. The most common place is the `OnApplicationInitialization` method of your module: ````csharp -using Volo.Abp.BackgroundWorkers; - public class MyModule : AbpModule { public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -76,8 +59,17 @@ public class MyModule : AbpModule context.ServiceProvider .GetRequiredService() .Add( - context.ServiceProvider.GetRequiredService() + context.ServiceProvider.GetRequiredService() ); } } -```` \ No newline at end of file +```` + +While we generally add workers in OnApplicationInitialization, there are no restrictions on that. You can inject IBackgroundWorkerManager anywhere and add workers at runtime. IBackgroundWorkerManager will stop and release all registered workers when your application is being shut down. + +## Making Your Application Always Run + +Background jobs and workers only work if your application is running. If you host the background job execution in your web application (this is the default behavior), you should ensure that your web application is configured to always be running. Otherwise, background jobs only work while your application is in use. + +## See More +* [Background Jobs](Background-Jobs.md) \ No newline at end of file From 9e6f8411943096bdf201692528748ca7e3b7df35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C3=87otur?= Date: Fri, 6 Mar 2020 16:41:57 +0300 Subject: [PATCH 5/9] Update Background-Workers.md --- docs/en/Background-Workers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/Background-Workers.md b/docs/en/Background-Workers.md index 4f7faffc71..9e9886b320 100644 --- a/docs/en/Background-Workers.md +++ b/docs/en/Background-Workers.md @@ -45,7 +45,7 @@ public class PassiveUserCheckerWorker : AsyncPeriodicBackgroundWorkerBase ```` * If your background worker derive from `PeriodicBackgroundWorkerBase`, you should implement the `DoWork` method to perform your periodic working code. -* If you directly implement IBackgroundWorker, you will override/implement the Start and Stop methods. +* If you directly implement IBackgroundWorker, you will override/implement the `StartAsync` and `StopAsync` methods. ### Register Background Worker From c7527cb6267c4f0b58b7d1ec66ac2ea3595e8dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C3=87otur?= Date: Fri, 6 Mar 2020 16:47:57 +0300 Subject: [PATCH 6/9] updated --- docs/en/Background-Jobs.md | 2 +- docs/en/Background-Workers.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/Background-Jobs.md b/docs/en/Background-Jobs.md index b5dce34ddf..a0ea708896 100644 --- a/docs/en/Background-Jobs.md +++ b/docs/en/Background-Jobs.md @@ -173,5 +173,5 @@ See pre-built job manager alternatives: * [Hangfire Background Job Manager](Background-Jobs-Hangfire.md) * [RabbitMQ Background Job Manager](Background-Jobs-RabbitMq.md) -## See More +## See Also * [Background Workers](Background-Workers.md) \ No newline at end of file diff --git a/docs/en/Background-Workers.md b/docs/en/Background-Workers.md index 9e9886b320..2257c0c2c2 100644 --- a/docs/en/Background-Workers.md +++ b/docs/en/Background-Workers.md @@ -71,5 +71,5 @@ While we generally add workers in OnApplicationInitialization, there are no rest Background jobs and workers only work if your application is running. If you host the background job execution in your web application (this is the default behavior), you should ensure that your web application is configured to always be running. Otherwise, background jobs only work while your application is in use. -## See More +## See Also * [Background Jobs](Background-Jobs.md) \ No newline at end of file From 7021afc0f9cc3e549caf68a8cc76bbc9fb7d4f57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C3=87otur?= Date: Fri, 6 Mar 2020 20:45:18 +0300 Subject: [PATCH 7/9] Create Buttons.md --- docs/en/AspNetCore/Tag-Helpers/Buttons.md | 70 +++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 docs/en/AspNetCore/Tag-Helpers/Buttons.md diff --git a/docs/en/AspNetCore/Tag-Helpers/Buttons.md b/docs/en/AspNetCore/Tag-Helpers/Buttons.md new file mode 100644 index 0000000000..a0685c8d3b --- /dev/null +++ b/docs/en/AspNetCore/Tag-Helpers/Buttons.md @@ -0,0 +1,70 @@ +# Buttons + +ABP framework has a special Tag Helper to create bootstrap button easily. + +`` + +## Attributes + +`` has 7 different attribute. + +* [`button-type`](#`button-type`) +* [`size`](#`size`) +* [`busy-text`](#`busy-text`) +* [`text`](#`text`) +* `icon` +* `disabled` +* `icon-type` + + +### `button-type` + +`button-type` is a selectable parameter. + +`Button` + +You can choose one of the button type listed below. + +* `Default` +* `Primary` +* `Secondary` +* `Success` +* `Danger` +* `Warning` +* `Info` +* `Light` +* `Dark` +* `Outline_Primary` +* `Outline_Secondary` +* `Outline_Success` +* `Outline_Danger` +* `Outline_Warning` +* `Outline_Info` +* `Outline_Light` +* `Outline_Dark` +* `Link` + +### `size` + +`size` is a selectable parameter. + +`Button` + +You can choose one of the size type listed below. + +* `Default` +* `Small` +* `Medium` +* `Large` +* `Block` +* `Block_Small` +* `Block_Medium` +* `Block_Large` + +### `busy-text` + +`busy-text` is a string parameter. IT shows the text while the button is busy. + +### `text` + +`text` is a string parameter that displaying on button. \ No newline at end of file From df4d3dc6d63cc333780b349d1847212fc8b1aaa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C3=87otur?= Date: Fri, 6 Mar 2020 21:11:30 +0300 Subject: [PATCH 8/9] Update Background-Workers.md --- docs/en/Background-Workers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/Background-Workers.md b/docs/en/Background-Workers.md index 2257c0c2c2..5da2c7532e 100644 --- a/docs/en/Background-Workers.md +++ b/docs/en/Background-Workers.md @@ -45,7 +45,7 @@ public class PassiveUserCheckerWorker : AsyncPeriodicBackgroundWorkerBase ```` * If your background worker derive from `PeriodicBackgroundWorkerBase`, you should implement the `DoWork` method to perform your periodic working code. -* If you directly implement IBackgroundWorker, you will override/implement the `StartAsync` and `StopAsync` methods. + ### Register Background Worker From 642caf4376da4ea021b74f35855d9ca31295a1b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C3=87otur?= Date: Fri, 6 Mar 2020 21:24:52 +0300 Subject: [PATCH 9/9] Delete Buttons.md --- docs/en/AspNetCore/Tag-Helpers/Buttons.md | 70 ----------------------- 1 file changed, 70 deletions(-) delete mode 100644 docs/en/AspNetCore/Tag-Helpers/Buttons.md diff --git a/docs/en/AspNetCore/Tag-Helpers/Buttons.md b/docs/en/AspNetCore/Tag-Helpers/Buttons.md deleted file mode 100644 index a0685c8d3b..0000000000 --- a/docs/en/AspNetCore/Tag-Helpers/Buttons.md +++ /dev/null @@ -1,70 +0,0 @@ -# Buttons - -ABP framework has a special Tag Helper to create bootstrap button easily. - -`` - -## Attributes - -`` has 7 different attribute. - -* [`button-type`](#`button-type`) -* [`size`](#`size`) -* [`busy-text`](#`busy-text`) -* [`text`](#`text`) -* `icon` -* `disabled` -* `icon-type` - - -### `button-type` - -`button-type` is a selectable parameter. - -`Button` - -You can choose one of the button type listed below. - -* `Default` -* `Primary` -* `Secondary` -* `Success` -* `Danger` -* `Warning` -* `Info` -* `Light` -* `Dark` -* `Outline_Primary` -* `Outline_Secondary` -* `Outline_Success` -* `Outline_Danger` -* `Outline_Warning` -* `Outline_Info` -* `Outline_Light` -* `Outline_Dark` -* `Link` - -### `size` - -`size` is a selectable parameter. - -`Button` - -You can choose one of the size type listed below. - -* `Default` -* `Small` -* `Medium` -* `Large` -* `Block` -* `Block_Small` -* `Block_Medium` -* `Block_Large` - -### `busy-text` - -`busy-text` is a string parameter. IT shows the text while the button is busy. - -### `text` - -`text` is a string parameter that displaying on button. \ No newline at end of file