Skip to content

Commit

Permalink
address PR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianburckhardt committed Oct 29, 2020
1 parent e2d768a commit be33048
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ internal class DurableClient : IDurableClient,

string IDurableEntityClient.TaskHubName => this.TaskHubName;

/// <inheritdoc/>
public override string ToString()
{
return $"DurableClient[backend={this.config.GetBackendInfo()}]";
Expand Down Expand Up @@ -534,10 +535,14 @@ async Task<CleanEntityStorageResult> IDurableEntityClient.CleanEntityStorageAsyn
tasks.Add(CheckForOrphanedLockAndFixIt(state, status.LockedBy));
}

if (removeEmptyEntities && !status.EntityExists && status.LockedBy == null && status.QueueSize == 0
&& now - state.LastUpdatedTime > this.config.MessageReorderWindow)
if (removeEmptyEntities)
{
tasks.Add(DeleteIdleOrchestrationEntity(state));
bool isEmptyEntity = !status.EntityExists && status.LockedBy == null && status.QueueSize == 0;
bool safeToRemoveWithoutBreakingMessageSorterLogic = now - state.LastUpdatedTime > this.config.MessageReorderWindow;
if (isEmptyEntity && safeToRemoveWithoutBreakingMessageSorterLogic)
{
tasks.Add(DeleteIdleOrchestrationEntity(state));
}
}
}

Expand Down
18 changes: 14 additions & 4 deletions src/WebJobs.Extensions.DurableTask/HttpApiHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,31 @@ private static TemplateMatcher GetInstanceRaiseEventRoute()

IDurableOrchestrationClient client = this.GetClient(request);
Stopwatch stopwatch = Stopwatch.StartNew();

// This retry loop completes either when the
// orchestration has completed, or when the timeout is reached.
while (true)
{
DurableOrchestrationStatus status = null;

if (client is DurableClient durableClient && durableClient.DurabilityProvider.SupportsPollFreeWait)
{
// For durability providers that support efficient (poll-free) waiting, we take advantage of that API
try
{
var state = await durableClient.DurabilityProvider.WaitForOrchestrationAsync(instanceId, null, timeout, CancellationToken.None);
status = DurableClient.ConvertOrchestrationStateToStatus(state);
}
catch (TimeoutException)
{
// The orchestration did not complete.
// Depending on the implementation of the backend, we may get here before the full timeout has elapsed,
// so we recheck how much time has elapsed below, and retry if there is time left.
}
}
else
{
// For durability providers that do not support efficient (poll-free) waiting, we do explicit retries.
status = await client.GetStatusAsync(instanceId);
}

Expand Down Expand Up @@ -717,13 +725,15 @@ private static bool TryGetIntQueryParameterValue(NameValueCollection queryString
TimeSpan? timeout = GetTimeSpan(request, "timeout");
TimeSpan? pollingInterval = GetTimeSpan(request, "pollingInterval");

if (timeout.HasValue && pollingInterval.HasValue)
// for durability providers that support poll-free waiting, we override the specified polling interval
if (client is DurableClient durableClient && durableClient.DurabilityProvider.SupportsPollFreeWait)
{
return await client.WaitForCompletionOrCreateCheckStatusResponseAsync(request, id, timeout.Value, pollingInterval.Value);
pollingInterval = timeout;
}
else if (timeout.HasValue && client is DurableClient durableClient && durableClient.DurabilityProvider.SupportsPollFreeWait)

if (timeout.HasValue && pollingInterval.HasValue)
{
return await client.WaitForCompletionOrCreateCheckStatusResponseAsync(request, id, timeout.Value, timeout.Value);
return await client.WaitForCompletionOrCreateCheckStatusResponseAsync(request, id, timeout.Value, pollingInterval.Value);
}
else
{
Expand Down

0 comments on commit be33048

Please sign in to comment.