using Quadarax.Foundation.Core.Business.Processor.Enums;
using Quadarax.Foundation.Core.Business.Processor.Exceptons;
namespace Quadarax.Foundation.Core.Business.Processor.Task;
public interface ITaskItem : ITaskIdentifier, ITimeTracked
{
#region *** Properties ***
///
/// Contains the affinity token which is used to identify owning/locking queue.
///
IAffinityToken AffinityToken { get; }
///
/// External reference of the task.
///
public string Reference { get; }
///
/// Status of the task.
///
public ProcessStatusEnum Status { get; }
///
/// Assembly qualified name of the provider class responsible to process task.
///
public string ProviderClass { get; }
///
/// Task priority value (0-maximal, 255-minimal / default 100).
///
public byte Priority { get; }
///
/// Time when task can be processed.
///
public DateTime ProcessingValidFrom { get; }
///
/// Time when task will be expired.
///
public DateTime? ProcessingValidTo { get; }
///
/// Defines single attempt timeout. If null, timeout is not used.
///
public TimeSpan? AttemptTimeout { get; }
///
/// Decremental counter of attempts to try process task.
///
public int AttemptsLeft { get; }
///
/// Statistical timestamp when task begins to process.
///
public DateTime StatStarted { get; }
///
/// Statistical timestamp when task finished.
///
public DateTime StatFinished { get; }
///
/// Latest attempt duration
///
public TimeSpan StatLastAttemptDuration { get; }
///
/// Collection of task status changes history log items. Ordered by descending.
///
public ITaskStatusLogItem[] StatusLog { get; }
#endregion
#region *** Operations ***
///
/// Re-Schedules inactive task to future and sets to (affects and ).
///
/// - Allowed state: ,
/// - Set state to:
///
/// When task state is invalid for operation.
///
/// Interval to shift to future.
/// Reason message to postpone.
void Postpone(TimeSpan postponeInterval, string reason);
///
/// Stops running task and sets to or
/// or (target status is depends on input arguments)..
///
/// - Allowed state:
/// - Set state to: or or
///
/// When task state is invalid for operation.
///
/// Reason message to stop.
/// If true, then will be set to otherwise to or .
/// If true, then will be set to otherwise to .
void Stop(string reason, bool willPause = true, bool willFail = false);
///
/// Resets task to initial state and sets to .
/// Uses current validity to re-calculate and to now + .
///
/// - Allowed state: , , ,
/// - Set state to:
///
/// When task state is invalid for operation.
///
/// Reason to reset task.
/// Postpone current validity from now.
void Reset(string reason, TimeSpan postponeValid);
///
/// Deletes task and sets to .
///
/// Reason to delete current task.
/// Flag is true, deletes task immediately (afters status change)
void Delete(string reason, bool immediate = false);
#endregion
}