Skip to content

Add Timeout support to PurgeInstancesFilter for partial purge#679

Closed
YunchuWang wants to merge 1 commit intomainfrom
wangbill/partial-purge-timeout
Closed

Add Timeout support to PurgeInstancesFilter for partial purge#679
YunchuWang wants to merge 1 commit intomainfrom
wangbill/partial-purge-timeout

Conversation

@YunchuWang
Copy link
Member

Summary

Add TimeSpan? Timeout property to PurgeInstancesFilter and send it as google.protobuf.Duration in the gRPC proto request, enabling time-bounded partial purge operations.

Motivation

When purging large numbers of orchestration instances through the isolated worker SDK, the gRPC call between worker and host times out before the purge completes. The caller receives OperationCanceledException while the host-side purge continues silently — making progress invisible and counts unreliable.

With this change, callers can set a timeout (e.g., 25 seconds) on each purge call. The operation returns within the timeout with accurate counts and an IsComplete flag, allowing the caller to loop until all instances are purged.

Changes

  • PurgeInstancesFilter: Add TimeSpan? Timeout { get; init; } property
  • GrpcDurableTaskClient.PurgeAllInstancesAsync: Send timeout as google.protobuf.Duration in proto request
  • Proto: Add google.protobuf.Duration timeout = 4 to PurgeInstanceFilter message

Usage

var filter = new PurgeInstancesFilter(
    CreatedFrom: DateTimeOffset.MinValue,
    CreatedTo: DateTimeOffset.UtcNow.AddMinutes(-5))
{
    Timeout = TimeSpan.FromSeconds(25),
};

bool isComplete = false;
int totalPurged = 0;
while (!isComplete)
{
    PurgeResult result = await client.PurgeAllInstancesAsync(filter);
    totalPurged += result.PurgedInstanceCount;
    isComplete = result.IsComplete ?? true;
}

Breaking Changes

None. The Timeout property is optional with a default of null (existing behavior unchanged).

Dependencies

- Add TimeSpan? Timeout property to PurgeInstancesFilter
- Send timeout as google.protobuf.Duration in gRPC PurgeInstanceFilter
- Add timeout field (4) to PurgeInstanceFilter proto message
- Enables callers to purge in time-bounded batches, checking IsComplete to loop
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds client-initiated, time-bounded purge support by extending the purge filter API and wiring the new value through the gRPC request contract, enabling iterative “partial purge” loops that return within a caller-specified time budget.

Changes:

  • Add TimeSpan? Timeout to PurgeInstancesFilter (public API) for per-call purge time bounding.
  • Extend PurgeInstanceFilter proto message with google.protobuf.Duration timeout = 4.
  • Map PurgeInstancesFilter.Timeout into the gRPC request in GrpcDurableTaskClient.PurgeAllInstancesAsync.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/Grpc/orchestrator_service.proto Adds timeout duration field to the purge filter proto message.
src/Client/Grpc/GrpcDurableTaskClient.cs Sends Timeout as a protobuf Duration when provided.
src/Client/Core/PurgeInstancesFilter.cs Introduces the new Timeout property and documents intended semantics.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +491 to +494
if (filter?.Timeout is not null)
{
request.PurgeInstanceFilter.Timeout = Google.Protobuf.WellKnownTypes.Duration.FromTimeSpan(filter.Timeout.Value);
}
Comment on lines +20 to +22
/// When set, the purge stops accepting new instances after this duration elapses
/// and returns with <see cref="PurgeResult.IsComplete"/> set to <c>false</c>.
/// Already-started instance deletions will complete before the method returns.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants