-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IInitializerTimeout and message to ErrorWithObject overload (#83)
Timeout for IInitializer and overload with message for ErrorWithObject
- Loading branch information
Showing
5 changed files
with
138 additions
and
58 deletions.
There are no files selected for viewing
11 changes: 5 additions & 6 deletions
11
ATI.Services.Common/Initializers/InitializeOrderAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
using System; | ||
|
||
namespace ATI.Services.Common.Initializers | ||
namespace ATI.Services.Common.Initializers; | ||
|
||
[AttributeUsage(AttributeTargets.Class)] | ||
public class InitializeOrderAttribute : Attribute | ||
{ | ||
[AttributeUsage(AttributeTargets.Class)] | ||
public class InitializeOrderAttribute : Attribute | ||
{ | ||
public InitializeOrder Order { get; set; } | ||
} | ||
public InitializeOrder Order { get; set; } | ||
} |
30 changes: 30 additions & 0 deletions
30
ATI.Services.Common/Initializers/InitializeTimeoutAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
|
||
namespace ATI.Services.Common.Initializers; | ||
|
||
/// <summary> | ||
/// Attribute for setting initialization timeout and behavior in case of timeout | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class)] | ||
public class InitializeTimeoutAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// Total initialization timeout in seconds | ||
/// When set, enables timeout for initialization, | ||
/// in case of Timeout and Required = true, application will not start | ||
/// in case of Timeout and Required = false, application will start without waiting for initialization if this service | ||
/// Default value is 10 seconds | ||
/// </summary> | ||
public int InitTimeoutSec { get; set; } = 10; | ||
|
||
/// <summary> | ||
/// Number of retries on exception | ||
/// </summary> | ||
public int Retry { get; set; } = 0; | ||
|
||
/// <summary> | ||
/// Is initialization required | ||
/// When true, application will not start if initialization failed due to timeout or exception | ||
/// </summary> | ||
public bool Required { get; set; } = false; | ||
} |
43 changes: 21 additions & 22 deletions
43
ATI.Services.Common/Initializers/Interfaces/IInitializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,25 @@ | ||
using System.Threading.Tasks; | ||
using ATI.Services.Common.Variables; | ||
|
||
namespace ATI.Services.Common.Initializers.Interfaces | ||
{ | ||
/// <summary> | ||
/// Интерфейс который маркирует объект, как требующий инициализации на старте приложения | ||
/// используется классом <see cref="StartupInitializer"/> | ||
/// для задания порядка инициализации используйте аттрибут <see cref="InitializeOrderAttribute"/> | ||
/// Имеющийся порядок на данный момент: | ||
/// ATI.Services.Authorization.AuthorizationInitializer - InitializeOrder.First | ||
/// <see cref="ServiceVariablesInitializer"/> - InitializeOrder.First | ||
/// <see cref="MetricsInitializer"/> - InitializeOrder.First | ||
/// <see cref="RedisInitializer"/> - InitializeOrder.Third | ||
/// <see cref="TwoLevelCacheInitializer"/> - InitializeOrder.Third | ||
/// <see cref="Caching.LocalCache.LocalCache{T}"/> - InitializeOrder.Fourth | ||
/// ATI.Services.Consul.ConsulInitializer - InitializeOrder.Sixth | ||
/// </summary> | ||
public interface IInitializer | ||
{ | ||
Task InitializeAsync(); | ||
string InitStartConsoleMessage(); | ||
string InitEndConsoleMessage(); | ||
|
||
} | ||
namespace ATI.Services.Common.Initializers.Interfaces; | ||
|
||
/// <summary> | ||
/// Интерфейс который маркирует объект, как требующий инициализации на старте приложения | ||
/// используется классом <see cref="StartupInitializer"/> | ||
/// <para>Для управления временем и поведением инициацлизации используйте <see cref="InitializeTimeoutAttribute"/></para> | ||
/// для задания порядка инициализации используйте аттрибут <see cref="InitializeOrderAttribute"/> | ||
/// Имеющийся порядок на данный момент: | ||
/// ATI.Services.Authorization.AuthorizationInitializer - InitializeOrder.First | ||
/// <see cref="ServiceVariablesInitializer"/> - InitializeOrder.First | ||
/// <see cref="MetricsInitializer"/> - InitializeOrder.First | ||
/// <see cref="RedisInitializer"/> - InitializeOrder.Third | ||
/// <see cref="TwoLevelCacheInitializer"/> - InitializeOrder.Third | ||
/// <see cref="Caching.LocalCache.LocalCache{T}"/> - InitializeOrder.Fourth | ||
/// ATI.Services.Consul.ConsulInitializer - InitializeOrder.Sixth | ||
/// </summary> | ||
public interface IInitializer | ||
{ | ||
Task InitializeAsync(); | ||
string InitStartConsoleMessage(); | ||
string InitEndConsoleMessage(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters