PsQueue.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using qdr.fnd.core.pqueue.Configuration;
  2. using qdr.fnd.core.pqueue.Enums;
  3. using qdr.fnd.core.pqueue.Exceptions;
  4. using qdr.fnd.core.pqueue.Process;
  5. using qdr.fnd.core.pqueue.Storages;
  6. using Quadarax.Foundation.Core.Data;
  7. using Quadarax.Foundation.Core.Logging;
  8. using Quadarax.Foundation.Core.Object;
  9. using Quadarax.Foundation.Core.Value.Generators;
  10. namespace qdr.fnd.core.pqueue
  11. {
  12. public class PsQueue : DisposableObject
  13. {
  14. #region *** Properties ***
  15. public string Name { get; }
  16. public bool IsRunning { get; private set; }
  17. public PsQueueConfiguration Configuration { get;}
  18. public event PsQueueStatusChangedEventHandler? ProcessItemStatusChanged;
  19. #endregion
  20. #region *** Private Fields ***
  21. private ILog _log;
  22. private TinyHash _hashGenerator;
  23. protected IPsQueueStorage? _storage;
  24. #endregion
  25. #region *** Constructors ***
  26. public PsQueue(string queueName, PsQueueConfiguration configuration,IPsQueueStorage storageProvider, ILogger logger)
  27. {
  28. _hashGenerator = new TinyHash(5);
  29. if (string.IsNullOrEmpty(queueName))
  30. queueName = "PSQUEUE" + _hashGenerator.NewId();
  31. Name = queueName;
  32. IsRunning = false;
  33. Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
  34. _storage = storageProvider ?? throw new ArgumentNullException(nameof(storageProvider));
  35. _log = logger.GetLogger(queueName);
  36. }
  37. #endregion
  38. #region *** Public Operations ***
  39. public void Start()
  40. {
  41. if (IsRunning) throw new PSQueueException(PSQueueException.ErrorCodes.PsQueueIsRunning);
  42. _log.Log(LogSeverityEnum.Info, $"{Name}:queue started.");
  43. }
  44. public void Stop()
  45. {
  46. if (!IsRunning) throw new PSQueueException(PSQueueException.ErrorCodes.PsQueueIsRunning);
  47. _log.Log(LogSeverityEnum.Info, $"{Name}:queue stopped.");
  48. }
  49. public string EnQueue(IPsQueueItemDescriptor item)
  50. {
  51. throw new NotImplementedException();
  52. }
  53. public bool Dequeue(string itemId, bool force)
  54. {
  55. throw new NotImplementedException();
  56. }
  57. public IQueryable<IPsQueueItem> Query(string? owner, string? ownerRef, params Tuple<bool,PsStatusEnum>[] status)
  58. {
  59. throw new NotImplementedException();
  60. }
  61. public IPsQueueItem? Get(string itemId)
  62. {
  63. throw new NotImplementedException();
  64. }
  65. public bool Postpone(string itemId, TimeSpan postpone)
  66. {
  67. throw new NotImplementedException();
  68. }
  69. public bool Reset(string itemId)
  70. {
  71. throw new NotImplementedException();
  72. }
  73. public bool SetPriority(string itemId, int priority)
  74. {
  75. throw new NotImplementedException();
  76. }
  77. public IEnumerable<IPsQueueItem> GetWorkingItems()
  78. {
  79. throw new NotImplementedException();
  80. }
  81. #endregion
  82. #region *** Private Operations ***
  83. protected override void OnDisposing()
  84. {
  85. if(IsRunning)
  86. Stop();
  87. ProcessItemStatusChanged = null;
  88. _storage = null;
  89. //TODO: Implement OnDisposing
  90. }
  91. #endregion
  92. }
  93. }