Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Purge instance history support #704

Merged
merged 4 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/DurableTask.AzureStorage/AzureStorageOrchestrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public sealed class AzureStorageOrchestrationService :
IOrchestrationService,
IOrchestrationServiceClient,
IDisposable,
IOrchestrationServiceQueryClient
IOrchestrationServiceQueryClient,
IOrchestrationServicePurgeClient
{
static readonly HistoryEvent[] EmptyHistoryEventList = new HistoryEvent[0];

Expand Down Expand Up @@ -1788,6 +1789,23 @@ public Task<PurgeHistoryResult> PurgeInstanceHistoryAsync(DateTime createdTimeFr
return this.trackingStore.PurgeInstanceHistoryAsync(createdTimeFrom, createdTimeTo, runtimeStatus);
}

/// <inheritdoc />
async Task<PurgeResult> IOrchestrationServicePurgeClient.PurgeInstanceStateAsync(string instanceId)
{
PurgeHistoryResult storagePurgeHistoryResult = await this.PurgeInstanceHistoryAsync(instanceId);
return storagePurgeHistoryResult.ToCorePurgeHistoryResult();
}

/// <inheritdoc />
async Task<PurgeResult> IOrchestrationServicePurgeClient.PurgeInstanceStateAsync(PurgeInstanceFilter purgeInstanceFilter)
{
PurgeHistoryResult storagePurgeHistoryResult = await this.PurgeInstanceHistoryAsync(
purgeInstanceFilter.CreatedTimeFrom,
purgeInstanceFilter.CreatedTimeTo,
purgeInstanceFilter.RuntimeStatus);
return storagePurgeHistoryResult.ToCorePurgeHistoryResult();
}

/// <summary>
/// Wait for an orchestration to reach any terminal state within the given timeout
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions src/DurableTask.AzureStorage/PurgeHistoryResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace DurableTask.AzureStorage
{
using DurableTask.Core;

/// <summary>
/// Class to hold statistics about this execution of purge history
/// </summary>
Expand Down Expand Up @@ -45,5 +47,13 @@ public PurgeHistoryResult(int storageRequests, int instancesDeleted, int rowsDel
/// Number of rows deleted during this execution of purge history
/// </summary>
public int RowsDeleted { get; }

/// <summary>
/// Converts from AzureStorage.PurgeHistoryResult to Core.PurgeResult type
/// </summary>
public PurgeResult ToCorePurgeHistoryResult()
{
return new PurgeResult(this.InstancesDeleted);
}
}
}
37 changes: 37 additions & 0 deletions src/DurableTask.Core/IOrchestrationServicePurgeClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// ----------------------------------------------------------------------------------
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace DurableTask.Core
{
using System.Threading.Tasks;

/// <summary>
/// Orchestration Service client interface for purging orchestration instance state.
/// </summary>
public interface IOrchestrationServicePurgeClient
{
/// <summary>
/// Purge state for an orchestration with a specified instance ID.
/// </summary>
/// <param name="instanceId">Instance ID of the orchestration to purge.</param>
/// <returns>A <see cref="PurgeResult"/> object containing more information about the purged instance.</returns>
Task<PurgeResult> PurgeInstanceStateAsync(string instanceId);

/// <summary>
/// Purge state for orchestrations that match the specified parameters.
/// </summary>
/// <param name="purgeInstanceFilter">A <see cref="PurgeInstanceFilter"/> object that determines which orchestration instances to purge.</param>
/// <returns>A <see cref="PurgeResult"/> object containing more information about the purged instances.</returns>
Task<PurgeResult> PurgeInstanceStateAsync(PurgeInstanceFilter purgeInstanceFilter);
}
}
52 changes: 52 additions & 0 deletions src/DurableTask.Core/PurgeInstanceFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// ----------------------------------------------------------------------------------
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------
#nullable enable
namespace DurableTask.Core
{
using System;
using System.Collections.Generic;

/// <summary>
/// Criteria for selecting orchestration instances to purge.
/// </summary>
public class PurgeInstanceFilter
{
/// <summary>
/// Constructor for purge instance conditions
/// </summary>
/// <param name="createdTimeFrom">CreatedTime of orchestrations. Purges state of orchestrations created after this time.</param>
/// <param name="createdTimeTo">CreatedTime of orchestrations. Purges state of orchestrations created before this time.</param>
/// <param name="runtimeStatus">The runtime status of the orchestrations to purge.</param>
public PurgeInstanceFilter(DateTime createdTimeFrom, DateTime? createdTimeTo, IEnumerable<OrchestrationStatus>? runtimeStatus)
{
this.CreatedTimeFrom = createdTimeFrom;
this.CreatedTimeTo = createdTimeTo;
this.RuntimeStatus = runtimeStatus;
}

/// <summary>
/// CreatedTime of orchestrations. Purges state of orchestrations created after this time.
/// </summary>
public DateTime CreatedTimeFrom { get; }

/// <summary>
/// CreatedTime of orchestrations. Purges state of orchestrations created before this time.
/// </summary>
public DateTime? CreatedTimeTo { get; }

/// <summary>
/// The runtime status of the orchestrations to purge.
/// </summary>
public IEnumerable<OrchestrationStatus>? RuntimeStatus { get; }
}
}
35 changes: 35 additions & 0 deletions src/DurableTask.Core/PurgeResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// ----------------------------------------------------------------------------------
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace DurableTask.Core
{
/// <summary>
/// Class representing the result of a purge operation.
/// </summary>
public class PurgeResult
{
/// <summary>
/// Initializes a new instance of the <see cref="PurgeResult" /> class.
/// </summary>
/// <param name="deletedInstanceCount">The number of instances deleted.</param>
public PurgeResult(int deletedInstanceCount)
{
this.DeletedInstanceCount = deletedInstanceCount;
}

/// <summary>
/// Number of instances deleted during this execution of the purge operation.
/// </summary>
public int DeletedInstanceCount { get; }
}
}