ITaskItem.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using Quadarax.Foundation.Core.Business.Processor.Enums;
  2. using Quadarax.Foundation.Core.Business.Processor.Exceptons;
  3. namespace Quadarax.Foundation.Core.Business.Processor.Task;
  4. public interface ITaskItem : ITaskIdentifier, ITimeTracked
  5. {
  6. #region *** Properties ***
  7. /// <summary>
  8. /// Contains the affinity token which is used to identify owning/locking queue.
  9. /// </summary>
  10. IAffinityToken AffinityToken { get; }
  11. /// <summary>
  12. /// External reference of the task.
  13. /// </summary>
  14. public string Reference { get; }
  15. /// <summary>
  16. /// Status of the task.
  17. /// </summary>
  18. public ProcessStatusEnum Status { get; }
  19. /// <summary>
  20. /// Assembly qualified name of the provider class responsible to process task.
  21. /// </summary>
  22. public string ProviderClass { get; }
  23. /// <summary>
  24. /// Task priority value (0-maximal, 255-minimal / default 100).
  25. /// </summary>
  26. public byte Priority { get; }
  27. /// <summary>
  28. /// Time when task can be processed.
  29. /// </summary>
  30. public DateTime ProcessingValidFrom { get; }
  31. /// <summary>
  32. /// Time when task will be expired.
  33. /// </summary>
  34. public DateTime? ProcessingValidTo { get; }
  35. /// <summary>
  36. /// Defines single attempt timeout. If null, timeout is not used.
  37. /// </summary>
  38. public TimeSpan? AttemptTimeout { get; }
  39. /// <summary>
  40. /// Decremental counter of attempts to try process task.
  41. /// </summary>
  42. public int AttemptsLeft { get; }
  43. /// <summary>
  44. /// Statistical timestamp when task begins to process.
  45. /// </summary>
  46. public DateTime StatStarted { get; }
  47. /// <summary>
  48. /// Statistical timestamp when task finished.
  49. /// </summary>
  50. public DateTime StatFinished { get; }
  51. /// <summary>
  52. /// Latest attempt duration
  53. /// </summary>
  54. public TimeSpan StatLastAttemptDuration { get; }
  55. /// <summary>
  56. /// Collection of task status changes history log items. Ordered by <see cref="ITaskStatusLogItem.Created"/> descending.
  57. /// </summary>
  58. public ITaskStatusLogItem[] StatusLog { get; }
  59. #endregion
  60. #region *** Operations ***
  61. /// <summary>
  62. /// Re-Schedules inactive task to future and sets <see cref="Status"/> to <see cref="ProcessStatusEnum.Pending"/> (affects <see cref="ProcessingValidFrom"/> and <see cref="ProcessingValidTo"/>).
  63. /// <list type="bullet">
  64. /// <item><description>Allowed state: <see cref="ProcessStatusEnum.Pending"/>, <see cref="ProcessStatusEnum.Paused"/></description></item>
  65. /// <item><description>Set state to: <see cref="ProcessStatusEnum.Pending"/></description></item>
  66. /// </list>
  67. /// <exception cref="InvalidTaskStateException">When task state is invalid for operation.</exception>
  68. /// </summary>
  69. /// <param name="postponeInterval">Interval to shift to future.</param>
  70. /// <param name="reason">Reason message to postpone.</param>
  71. void Postpone(TimeSpan postponeInterval, string reason);
  72. /// <summary>
  73. /// Stops running task and sets <see cref="Status"/> to <see cref="ProcessStatusEnum.Paused"/> or
  74. /// <see cref="ProcessStatusEnum.ProcessedSucc"/> or <see cref="ProcessStatusEnum.ProcessedFail"/> (target status is depends on input arguments)..
  75. /// <list type="bullet">
  76. /// <item><description>Allowed state: <see cref="ProcessStatusEnum.Started"/></description></item>
  77. /// <item><description>Set state to: <see cref="ProcessStatusEnum.Paused"/> or <see cref="ProcessStatusEnum.ProcessedSucc"/> or <see cref="ProcessStatusEnum.ProcessedFail"/></description></item>
  78. /// </list>
  79. /// <exception cref="InvalidTaskStateException">When task state is invalid for operation.</exception>
  80. /// </summary>
  81. /// <param name="reason">Reason message to stop.</param>
  82. /// <param name="willPause">If true, then <see cref="Status"/> will be set to <see cref="ProcessStatusEnum.Paused"/> otherwise to <see cref="ProcessStatusEnum.ProcessedSucc"/> or <see cref="ProcessStatusEnum.ProcessedFail"/>.</param>
  83. /// <param name="willFail">If true, then <see cref="Status"/> will be set to <see cref="ProcessStatusEnum.ProcessedFail"/> otherwise to <see cref="ProcessStatusEnum.ProcessedSucc"/>.</param>
  84. void Stop(string reason, bool willPause = true, bool willFail = false);
  85. /// <summary>
  86. /// Resets task to initial state and sets <see cref="Status"/> to <see cref="ProcessStatusEnum.Pending"/>.
  87. /// Uses current validity to re-calculate <see cref="ProcessingValidFrom"/> and <see cref="ProcessingValidTo"/> to now + <see cref="postponeValid"/>.
  88. /// <list type="bullet">
  89. /// <item><description>Allowed state: <see cref="ProcessStatusEnum.Attached"/>, <see cref="ProcessStatusEnum.ProcessedSucc"/>, <see cref="ProcessStatusEnum.ProcessedFail"/>, <see cref="ProcessStatusEnum.Paused"/></description></item>
  90. /// <item><description>Set state to: <see cref="ProcessStatusEnum.Pending"/></description></item>
  91. /// </list>
  92. /// <exception cref="InvalidTaskStateException">When task state is invalid for operation.</exception>
  93. /// </summary>
  94. /// <param name="reason">Reason to reset task.</param>
  95. /// <param name="postponeValid">Postpone current validity from now.</param>
  96. void Reset(string reason, TimeSpan postponeValid);
  97. /// <summary>
  98. /// Deletes task and sets <see cref="Status"/> to <see cref="ProcessStatusEnum.Deleted"/>.
  99. /// </summary>
  100. /// <param name="reason">Reason to delete current task.</param>
  101. /// <param name="immediate">Flag is true, deletes task immediately (afters status change)</param>
  102. void Delete(string reason, bool immediate = false);
  103. #endregion
  104. }