PsQueueConfiguration.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using qdr.fnd.core.pqueue.Storages;
  2. using Quadarax.Foundation.Core.Data;
  3. namespace qdr.fnd.core.pqueue.Configuration
  4. {
  5. /// <summary>
  6. /// Main PSQueue configuration object.
  7. /// </summary>
  8. public class PsQueueConfiguration
  9. {
  10. #region *** Properties ***
  11. /// <summary>
  12. /// Unique name of the queue, locally based on the application.
  13. /// </summary>
  14. public string QueueName { get; set; }
  15. /// <summary>
  16. /// Declare storage configuration for the queue.
  17. /// </summary>
  18. public PsQueueStorageConfiguration Storage { get; set; }
  19. /// <summary>
  20. /// Maximum number of concurrent processes that can be executed at once (How many threads uses).
  21. /// </summary>
  22. public int MaxConcurrentProcesses { get; set; }
  23. /// <summary>
  24. /// Defines the interval to check the queue for new items to process. If not specified, uses continuous strategy
  25. /// </summary>
  26. public TimeSpan? CycleInterval { get; set; }
  27. /// <summary>
  28. /// Default initial attempts for the queue items if not defined.
  29. /// </summary>
  30. public int? DefaultInitialAttempts { get; set; }
  31. /// <summary>
  32. /// Default process (one attempt) timeout for the queue items.
  33. /// </summary>
  34. public TimeSpan DefaultProcessTimeout { get; set; }
  35. /// <summary>
  36. /// Default attempt to postpone for the queue items when attempt failed. If not specified new attempt will be executed instantly
  37. /// </summary>
  38. public TimeSpan? DefaultAttemptPostpone { get; set; }
  39. /// <summary>
  40. /// Defines retention configuration for the queue.
  41. /// </summary>
  42. public PsQueueRetentionConfiguration? Retention { get; set; }
  43. #endregion
  44. #region *** Constructors ***
  45. public PsQueueConfiguration() : this(string.Empty)
  46. {
  47. }
  48. public PsQueueConfiguration(string queueName)
  49. {
  50. QueueName = queueName;
  51. Storage = new PsQueueStorageConfiguration();
  52. }
  53. #endregion
  54. #region *** Operations ***
  55. /// <summary>
  56. /// Create default configuration for the queue.
  57. /// </summary>
  58. /// <param name="queueName">Local unique queue name.</param>
  59. /// <returns></returns>
  60. public static PsQueueConfiguration Default(string queueName)
  61. {
  62. var config = new PsQueueConfiguration(queueName)
  63. {
  64. MaxConcurrentProcesses = 4,
  65. CycleInterval = TimeSpan.FromSeconds(10),
  66. DefaultInitialAttempts = 3,
  67. DefaultProcessTimeout = TimeSpan.FromSeconds(30),
  68. DefaultAttemptPostpone = TimeSpan.FromSeconds(30)
  69. };
  70. var storageProviderClass = typeof(MemoryStorageProvider).FullName;
  71. if (storageProviderClass != null)
  72. config.Storage.ProviderClass = storageProviderClass;
  73. config.Retention = new PsQueueRetentionConfiguration
  74. {
  75. Enabled = true,
  76. RetentionDoneOlder = TimeSpan.FromDays(7),
  77. RetentionDoneMaxCount = 1000,
  78. RetentionFailedOlder = TimeSpan.FromDays(7),
  79. RetentionFailedMaxCount = 1000
  80. };
  81. return config;
  82. }
  83. #endregion
  84. }
  85. /// <summary>
  86. /// Storage configuration for the queue.
  87. /// </summary>
  88. public class PsQueueStorageConfiguration
  89. {
  90. /// <summary>
  91. /// Qualified class name of the storage provider.
  92. /// </summary>
  93. public string ProviderClass { get; set; } = string.Empty;
  94. /// <summary>
  95. /// Storage source (path or connection string).
  96. /// </summary>
  97. public string Source { get; set; } = string.Empty;
  98. /// <summary>
  99. /// User identity for the storage provider or impersonation account.
  100. /// </summary>
  101. public string? UserName { get; set; }
  102. /// <summary>
  103. /// User password hashed by concat <see cref="PsQueueConfiguration.QueueName"/> and <see cref="UserName"/>.
  104. /// </summary>
  105. public string? UserPasswordHashed { get; set; }
  106. /// <summary>
  107. /// Provider specific configuration.
  108. /// </summary>
  109. public IList<TypedArgument>? Arguments { get; set; }
  110. }
  111. /// <summary>
  112. /// Retention configuration for the queue.
  113. /// </summary>
  114. public class PsQueueRetentionConfiguration
  115. {
  116. /// <summary>
  117. /// Flag to enable retention configuration.
  118. /// </summary>
  119. public bool Enabled { get; set; }
  120. /// <summary>
  121. /// Maximum time to keep the queue item that are Done in the queue.
  122. /// </summary>
  123. public TimeSpan? RetentionDoneOlder { get; set; }
  124. /// <summary>
  125. /// Maximum queue items that are Done in the queue.
  126. /// </summary>
  127. public int? RetentionDoneMaxCount { get; set; }
  128. /// <summary>
  129. /// Maximum time to keep the queue item that are Failed in the queue.
  130. /// </summary>
  131. public TimeSpan? RetentionFailedOlder { get; set; }
  132. /// <summary>
  133. /// Maximum queue items that are Failed in the queue.
  134. /// </summary>
  135. public int? RetentionFailedMaxCount { get; set; }
  136. }
  137. }