Skip to content

Commit

Permalink
fix should retry check
Browse files Browse the repository at this point in the history
  • Loading branch information
ZjzMisaka committed May 5, 2024
1 parent a901418 commit 9e0fae9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
16 changes: 12 additions & 4 deletions PowerThreadPool/Core/PowerThreadPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,10 @@ public bool Wait(string id)
{
return work.Wait();
}
return false;
else
{
return false;
}
}

/// <summary>
Expand Down Expand Up @@ -1472,7 +1475,10 @@ public bool Pause(string id)
{
return work.Pause();
}
return false;
else
{
return false;
}
}

/// <summary>
Expand Down Expand Up @@ -1584,8 +1590,10 @@ public bool Cancel(string id)
{
return work.Cancel(true);
}

return false;
else
{
return false;
}
}

/// <summary>
Expand Down
28 changes: 21 additions & 7 deletions PowerThreadPool/Works/Work.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,30 +225,44 @@ internal override ExecuteResultBase SetExecuteResult(object result, Exception ex
return executeResult;
}

internal override bool ShouldImmediateRetry(ExecuteResultBase executeResult)
internal override bool ShouldRetry(ExecuteResultBase executeResult)
{
if (executeResult != null && executeResult.RetryInfo != null && executeResult.RetryInfo.StopRetry)
{
return false;
}
else if (workOption.RetryOption != null && Status == Status.Failed && ((workOption.RetryOption.RetryBehavior == RetryBehavior.ImmediateRetry && workOption.RetryOption.RetryPolicy == RetryPolicy.Limited && ExecuteCount - 1 < workOption.RetryOption.MaxRetryCount) || workOption.RetryOption.RetryBehavior == RetryBehavior.ImmediateRetry && workOption.RetryOption.RetryPolicy == RetryPolicy.Unlimited))
else if (workOption.RetryOption != null && Status == Status.Failed && ((workOption.RetryOption.RetryPolicy == RetryPolicy.Limited && ExecuteCount - 1 < workOption.RetryOption.MaxRetryCount) || workOption.RetryOption.RetryPolicy == RetryPolicy.Unlimited))
{
return true;
}
return false;
else
{
return false;
}
}

internal override bool ShouldRequeue(ExecuteResultBase executeResult)
internal override bool ShouldImmediateRetry(ExecuteResultBase executeResult)
{
if (executeResult != null && executeResult.RetryInfo != null && executeResult.RetryInfo.StopRetry)
if (ShouldRetry(executeResult) && workOption.RetryOption.RetryBehavior == RetryBehavior.ImmediateRetry)
{
return true;
}
else
{
return false;
}
if (workOption.RetryOption != null && Status == Status.Failed && ((workOption.RetryOption.RetryBehavior == RetryBehavior.Requeue && workOption.RetryOption.RetryPolicy == RetryPolicy.Limited && ExecuteCount - 1 < workOption.RetryOption.MaxRetryCount) || workOption.RetryOption.RetryPolicy == RetryPolicy.Unlimited))
}

internal override bool ShouldRequeue(ExecuteResultBase executeResult)
{
if (ShouldRetry(executeResult) && workOption.RetryOption.RetryBehavior == RetryBehavior.Requeue)
{
return true;
}
return false;
else
{
return false;
}
}
}
}
1 change: 1 addition & 0 deletions PowerThreadPool/Works/WorkBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ internal abstract class WorkBase
internal abstract void UnlockWorker(Worker worker);
internal abstract void InvokeCallback(PowerPool powerPool, ExecuteResultBase executeResult, PowerPoolOption powerPoolOption);
internal abstract ExecuteResultBase SetExecuteResult(object result, Exception exception, Status status);
internal abstract bool ShouldRetry(ExecuteResultBase executeResult);
internal abstract bool ShouldImmediateRetry(ExecuteResultBase executeResult);
internal abstract bool ShouldRequeue(ExecuteResultBase executeResult);
internal abstract string Group { get; }
Expand Down

0 comments on commit 9e0fae9

Please sign in to comment.