ITaskItem.cs 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /// Decremental counter of attempts to try process task.
  37. /// </summary>
  38. public int AttemptsLeft { get; }
  39. /// <summary>
  40. /// Statistical timestamp when task begins to process.
  41. /// </summary>
  42. public DateTime StatStarted { get; }
  43. /// <summary>
  44. /// Statistical timestamp when task finished.
  45. /// </summary>
  46. public DateTime StatFinished { get; }
  47. /// <summary>
  48. /// Latest attempt duration
  49. /// </summary>
  50. public TimeSpan StatLastAttemptDuration { get; }
  51. #endregion
  52. #region *** Operations ***
  53. /// <summary>
  54. /// Re-Schedules inactive task to future and sets <see cref="Status"/> to <see cref="ProcessStatusEnum.Pending"/> (affects <see cref="ProcessingValidFrom"/> and <see cref="ProcessingValidTo"/>).
  55. /// <list type="bullet">
  56. /// <item><description>Allowed state: <see cref="ProcessStatusEnum.Pending"/>, <see cref="ProcessStatusEnum.Paused"/></description></item>
  57. /// <item><description>Set state to: <see cref="ProcessStatusEnum.Pending"/></description></item>
  58. /// </list>
  59. /// <exception cref="InvalidTaskStateException">When task state is invalid for operation.</exception>
  60. /// </summary>
  61. /// <param name="postponeInterval">Interval to shift to future.</param>
  62. /// <param name="reason">Reason message to postpone.</param>
  63. void Postpone(TimeSpan postponeInterval, string reason);
  64. /// <summary>
  65. /// Stops running task and sets <see cref="Status"/> to <see cref="ProcessStatusEnum.Paused"/> or
  66. /// <see cref="ProcessStatusEnum.ProcessedSucc"/> or <see cref="ProcessStatusEnum.ProcessedFail"/> (target status is depends on input arguments)..
  67. /// <list type="bullet">
  68. /// <item><description>Allowed state: <see cref="ProcessStatusEnum.Started"/></description></item>
  69. /// <item><description>Set state to: <see cref="ProcessStatusEnum.Paused"/> or <see cref="ProcessStatusEnum.ProcessedSucc"/> or <see cref="ProcessStatusEnum.ProcessedFail"/></description></item>
  70. /// </list>
  71. /// <exception cref="InvalidTaskStateException">When task state is invalid for operation.</exception>
  72. /// </summary>
  73. /// <param name="reason">Reason message to stop.</param>
  74. /// <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>
  75. /// <param name="willFail">If true, then <see cref="Status"/> will be set to <see cref="ProcessStatusEnum.ProcessedFail"/> otherwise to <see cref="ProcessStatusEnum.ProcessedSucc"/>.</param>
  76. void Stop(string reason, bool willPause = true, bool willFail = false);
  77. /// <summary>
  78. /// Resets task to initial state and sets <see cref="Status"/> to <see cref="ProcessStatusEnum.Pending"/>.
  79. /// Uses current validity to re-calculate <see cref="ProcessingValidFrom"/> and <see cref="ProcessingValidTo"/> to now + <see cref="postponeValid"/>.
  80. /// </summary>
  81. /// <param name="reason">Reason to reset task.</param>
  82. /// <param name="postponeValid">Postpone current validity from now.</param>
  83. void Reset(string reason, TimeSpan postponeValid);
  84. #endregion
  85. }