ProcessorSetting.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using Microsoft.CodeAnalysis.CSharp.Syntax;
  2. using Quadarax.Application.QLiberace.Common.Attributes;
  3. using Quadarax.Application.QLiberace.Common.Settings;
  4. using Quadarax.Application.QLiberace.Processor.Services;
  5. using Quadarax.Application.QLiberace.Processor.Workers;
  6. using Quadarax.Foundation.Core.Business.Interface;
  7. namespace Quadarax.Application.QLiberace.Processor.Settings
  8. {
  9. [Module(Base.Constants.Modules.Processor.Code)]
  10. public class ProcessorSetting : ModuleSetting
  11. {
  12. /// <summary>
  13. /// Defines number of <see cref="ProcessorWorkerService"/> working parallel
  14. /// </summary>
  15. public int Workers { get; set; }
  16. /// <summary>
  17. /// Defines number of <see cref="ProcessingWorker"/> working under one instance of <see cref="ProcessorWorkerService"/>
  18. /// </summary>
  19. public int ProcessingThreadsPerWorker { get; set; }
  20. /// <summary>
  21. /// Default processing worker PWI (Process Worker Identifier)
  22. /// </summary>
  23. public string ProcessingWorkerPwi { get; set; } = null!;
  24. /// <summary>
  25. /// Defines processing worker iteration interval (between two steps)
  26. /// </summary>
  27. public TimeSpan ProcessingWorkerInterval { get; set; }
  28. /// <summary>
  29. /// Defines processing worker iteration timeout (maximal iteration duration)
  30. /// </summary>
  31. public TimeSpan ProcessingWorkerTimeout { get; set; }
  32. /// <summary>
  33. /// Defines processing worker start delay two instances of worker (for fine tuning synchronization)
  34. /// </summary>
  35. public TimeSpan ProcessingWorkerDelay { get; set; }
  36. /// <summary>
  37. /// Defines number of <see cref="GarbageWorker"/> working under one instance of <see cref="ProcessorWorkerService"/>
  38. /// </summary>
  39. public int GarbageThreadsPerWorker { get; set; }
  40. /// <summary>
  41. /// Default garbage worker PWI (Process Worker Identifier)
  42. /// </summary>
  43. public string GarbageWorkerPwi { get; set; } = null!;
  44. /// <summary>
  45. /// Defines garbage worker iteration interval (between two steps)
  46. /// </summary>
  47. public TimeSpan GarbageWorkerInterval { get; set; }
  48. /// <summary>
  49. /// Defines garbage worker iteration timeout (maximal iteration duration)
  50. /// </summary>
  51. public TimeSpan GarbageWorkerTimeout { get; set; }
  52. /// <summary>
  53. /// Defines garbage worker start delay two instances of worker (for fine tuning synchronization)
  54. /// </summary>
  55. public TimeSpan GarbageWorkerDelay { get; set; }
  56. /// <summary>
  57. /// Defines number of <see cref="RetentionWorker"/> working under one instance of <see cref="ProcessorWorkerService"/>
  58. /// </summary>
  59. public int RetentionThreadsPerWorker { get; set; }
  60. /// <summary>
  61. /// Default retention worker PWI (Process Worker Identifier)
  62. /// </summary>
  63. public string RetentionWorkerPwi { get; set; } = null!;
  64. /// <summary>
  65. /// Defines retention worker iteration interval (between two steps)
  66. /// </summary>
  67. public TimeSpan RetentionWorkerInterval { get; set; }
  68. /// <summary>
  69. /// Defines retention worker iteration timeout (maximal iteration duration)
  70. /// </summary>
  71. public TimeSpan RetentionWorkerTimeout { get; set; }
  72. /// <summary>
  73. /// Defines retention worker start delay between two instances of worker (for fine tuning synchronization)
  74. /// </summary>
  75. public TimeSpan RetentionWorkerDelay { get; set; }
  76. #region *** Operations ***
  77. public IWorkerSettings GetProcessingWorkerSettings()
  78. {
  79. return new WorkerSettings()
  80. {
  81. Interval = ProcessingWorkerInterval,
  82. IterationTimeout = ProcessingWorkerTimeout,
  83. StartDelay = ProcessingWorkerDelay,
  84. WorkerCount = ProcessingThreadsPerWorker,
  85. WorkerNamePrefix = ProcessingWorkerPwi
  86. };
  87. }
  88. public IWorkerSettings GetGarbageWorkerSettings()
  89. {
  90. return new WorkerSettings()
  91. {
  92. Interval = GarbageWorkerInterval,
  93. IterationTimeout = GarbageWorkerTimeout,
  94. StartDelay = GarbageWorkerDelay,
  95. WorkerCount = GarbageThreadsPerWorker,
  96. WorkerNamePrefix = GarbageWorkerPwi
  97. };
  98. }
  99. public IWorkerSettings GetRetentionWorkerSettings()
  100. {
  101. return new WorkerSettings()
  102. {
  103. Interval = RetentionWorkerInterval,
  104. IterationTimeout = RetentionWorkerTimeout,
  105. StartDelay = RetentionWorkerDelay,
  106. WorkerCount = RetentionThreadsPerWorker,
  107. WorkerNamePrefix = RetentionWorkerPwi
  108. };
  109. }
  110. public override void SetDefaults()
  111. {
  112. Workers = Constants.Modules.Processor.ProcessorServiceCount;
  113. ProcessingThreadsPerWorker = Constants.Modules.Processor.ProcessingThreads;
  114. ProcessingWorkerPwi = Constants.Modules.Processor.PrefixProcessing;
  115. ProcessingWorkerInterval = TimeSpan.Parse(Constants.Modules.Processor.ProcessingInterval);
  116. ProcessingWorkerTimeout= TimeSpan.Parse(Constants.Modules.Processor.ProcessingTimeout);
  117. ProcessingWorkerDelay = TimeSpan.Parse(Constants.Modules.Processor.ProcessingDelay);
  118. GarbageThreadsPerWorker= Constants.Modules.Processor.GarbageThreads;
  119. GarbageWorkerPwi = Constants.Modules.Processor.PrefixGarbage;
  120. GarbageWorkerInterval= TimeSpan.Parse(Constants.Modules.Processor.GarbageInterval);
  121. GarbageWorkerTimeout = TimeSpan.Parse(Constants.Modules.Processor.GarbageTimeout);
  122. GarbageWorkerDelay= TimeSpan.Parse(Constants.Modules.Processor.GarbageDelay);
  123. RetentionThreadsPerWorker = Constants.Modules.Processor.RetentionThreads;
  124. RetentionWorkerPwi = Constants.Modules.Processor.PrefixRetention;
  125. RetentionWorkerInterval = TimeSpan.Parse(Constants.Modules.Processor.RetentionInterval);
  126. RetentionWorkerTimeout= TimeSpan.Parse(Constants.Modules.Processor.RetentionTimeout);
  127. RetentionWorkerDelay= TimeSpan.Parse(Constants.Modules.Processor.RetentionDelay);
  128. }
  129. #endregion
  130. #region *** Private operations ***
  131. #endregion
  132. #region *** Nested classes ***
  133. #endregion
  134. }
  135. }