using qdr.fnd.core.pqueue.Storages;
using Quadarax.Foundation.Core.Data;
namespace qdr.fnd.core.pqueue.Configuration
{
///
/// Main PSQueue configuration object.
///
public class PsQueueConfiguration
{
#region *** Properties ***
///
/// Unique name of the queue, locally based on the application.
///
public string QueueName { get; set; }
///
/// Declare storage configuration for the queue.
///
public PsQueueStorageConfiguration Storage { get; set; }
///
/// Maximum number of concurrent processes that can be executed at once (How many threads uses).
///
public int MaxConcurrentProcesses { get; set; }
///
/// Defines the interval to check the queue for new items to process. If not specified, uses continuous strategy
///
public TimeSpan? CycleInterval { get; set; }
///
/// Default initial attempts for the queue items if not defined.
///
public int? DefaultInitialAttempts { get; set; }
///
/// Default process (one attempt) timeout for the queue items.
///
public TimeSpan DefaultProcessTimeout { get; set; }
///
/// Default attempt to postpone for the queue items when attempt failed. If not specified new attempt will be executed instantly
///
public TimeSpan? DefaultAttemptPostpone { get; set; }
///
/// Defines retention configuration for the queue.
///
public PsQueueRetentionConfiguration? Retention { get; set; }
#endregion
#region *** Constructors ***
public PsQueueConfiguration() : this(string.Empty)
{
}
public PsQueueConfiguration(string queueName)
{
QueueName = queueName;
Storage = new PsQueueStorageConfiguration();
}
#endregion
#region *** Operations ***
///
/// Create default configuration for the queue.
///
/// Local unique queue name.
///
public static PsQueueConfiguration Default(string queueName)
{
var config = new PsQueueConfiguration(queueName)
{
MaxConcurrentProcesses = 4,
CycleInterval = TimeSpan.FromSeconds(10),
DefaultInitialAttempts = 3,
DefaultProcessTimeout = TimeSpan.FromSeconds(30),
DefaultAttemptPostpone = TimeSpan.FromSeconds(30)
};
var storageProviderClass = typeof(MemoryStorageProvider).FullName;
if (storageProviderClass != null)
config.Storage.ProviderClass = storageProviderClass;
config.Retention = new PsQueueRetentionConfiguration
{
Enabled = true,
RetentionDoneOlder = TimeSpan.FromDays(7),
RetentionDoneMaxCount = 1000,
RetentionFailedOlder = TimeSpan.FromDays(7),
RetentionFailedMaxCount = 1000
};
return config;
}
#endregion
}
///
/// Storage configuration for the queue.
///
public class PsQueueStorageConfiguration
{
///
/// Qualified class name of the storage provider.
///
public string ProviderClass { get; set; } = string.Empty;
///
/// Storage source (path or connection string).
///
public string Source { get; set; } = string.Empty;
///
/// User identity for the storage provider or impersonation account.
///
public string? UserName { get; set; }
///
/// User password hashed by concat and .
///
public string? UserPasswordHashed { get; set; }
///
/// Provider specific configuration.
///
public IList? Arguments { get; set; }
}
///
/// Retention configuration for the queue.
///
public class PsQueueRetentionConfiguration
{
///
/// Flag to enable retention configuration.
///
public bool Enabled { get; set; }
///
/// Maximum time to keep the queue item that are Done in the queue.
///
public TimeSpan? RetentionDoneOlder { get; set; }
///
/// Maximum queue items that are Done in the queue.
///
public int? RetentionDoneMaxCount { get; set; }
///
/// Maximum time to keep the queue item that are Failed in the queue.
///
public TimeSpan? RetentionFailedOlder { get; set; }
///
/// Maximum queue items that are Failed in the queue.
///
public int? RetentionFailedMaxCount { get; set; }
}
}