Skip to content

Commit

Permalink
Add fields canRerun and canCancel to task meta
Browse files Browse the repository at this point in the history
  • Loading branch information
gafetinov committed Nov 28, 2023
1 parent eeed1ce commit 4c7504b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IRtqMonitoringApi
{
[NotNull, ItemNotNull]
string[] GetAllTaskStates();

[NotNull, ItemNotNull]
string[] GetAllTasksNames();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public static RtqMonitoringTaskMeta ToMonitoringTaskMeta(this TaskMetaInformatio
State = meta.State,
Attempts = meta.Attempts,
ParentTaskId = meta.ParentTaskId,
CanCancel = meta.CanCancel(),
CanRerun = meta.CanRerun()
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,11 @@ public class RtqMonitoringTaskMeta

[JsonProperty("parentTaskId")]
public string ParentTaskId { get; set; }

[JsonProperty("canCancel")]
public bool CanCancel { get; set; }

[JsonProperty("canRerun")]
public bool CanRerun { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public string[] GetAllTaskStates()
{
throw new NotImplementedException();
}

public string[] GetAllTaskNames()
{
throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ internal List<TimeGuid> AddExceptionInfoId([NotNull] TimeGuid newExceptionInfoId
return TimeSpan.FromTicks(Math.Max(ExpirationTimestampTicks.Value - Timestamp.Now.Ticks, TimeSpan.TicksPerSecond));
}

public bool CanCancel()
{
return cancelableStates.Contains(State);
}

public bool CanRerun()
{
return rerunnableStates.Contains(State);
}

public void SetOrUpdateTtl(TimeSpan ttl)
{
var now = Timestamp.Now;
Expand Down Expand Up @@ -152,5 +162,14 @@ private static string TicksToString(long ticks)
}

public const int TaskExceptionIfoIdsLimit = 201;
private readonly TaskState[] cancelableStates = new[] {TaskState.New, TaskState.WaitingForRerun, TaskState.WaitingForRerunAfterError};

private readonly TaskState[] rerunnableStates = new[]
{
TaskState.Fatal,
TaskState.Finished,
TaskState.WaitingForRerun,
TaskState.WaitingForRerunAfterError
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace SkbKontur.Cassandra.DistributedTaskQueue.Configuration
public interface IRtqTaskDataRegistry
{
string[] GetAllTaskStates();

string[] GetAllTaskNames();

string GetTaskName(Type type);
Expand Down

0 comments on commit 4c7504b

Please sign in to comment.