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 2 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
25 changes: 24 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,28 @@ public Task<PurgeHistoryResult> PurgeInstanceHistoryAsync(DateTime createdTimeFr
return this.trackingStore.PurgeInstanceHistoryAsync(createdTimeFrom, createdTimeTo, runtimeStatus);
}

/// <summary>
/// Purge history for an orchestration with a specified instance id.
/// </summary>
/// <param name="instanceId">Instance ID of the orchestration.</param>
/// <returns><see cref="PurgeResult"/> object containing more information about the purged instance.</returns>
async Task<PurgeResult> IOrchestrationServicePurgeClient.PurgeInstanceStateAsync(string instanceId)
{
PurgeHistoryResult storagePurgeHistoryResult = await this.PurgeInstanceHistoryAsync(instanceId);
return storagePurgeHistoryResult.ToCorePurgeHistoryResult();
}

/// <summary>
/// Purge history for orchestrations that match the specified parameters.
/// </summary>
/// <param name="purgeInstanceCondition"><see cref="PurgeInstanceCondition"/>Conditions that should match to purge orchestration history.</param>
/// <returns><see cref="PurgeResult"/> object containing more information about the purged instance.</returns>
shreyas-gopalakrishna marked this conversation as resolved.
Show resolved Hide resolved
async Task<PurgeResult> IOrchestrationServicePurgeClient.PurgeInstanceStateAsync(PurgeInstanceCondition purgeInstanceCondition)
{
PurgeHistoryResult storagePurgeHistoryResult = await this.PurgeInstanceHistoryAsync(purgeInstanceCondition.CreatedTimeFrom, purgeInstanceCondition.CreatedTimeTo, purgeInstanceCondition.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);
}
}
}
39 changes: 39 additions & 0 deletions src/DurableTask.Core/IOrchestrationServicePurgeClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ----------------------------------------------------------------------------------
// 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 interface for purging instance history
/// </summary>
public interface IOrchestrationServicePurgeClient
{
// Purge instance history operations

/// <summary>
/// Purge history for an orchestration with a specified instance id.
/// </summary>
/// <param name="instanceId">Instance ID of the orchestration.</param>
/// <returns><see cref="PurgeResult"/> object containing more information about the purged instance.</returns>
Task<PurgeResult> PurgeInstanceStateAsync(string instanceId);

/// <summary>
/// Purge history for orchestrations that match the specified parameters.
/// </summary>
/// <param name="purgeInstanceCondition"><see cref="PurgeInstanceCondition"/>Conditions that should match to purge orchestration history.</param>
shreyas-gopalakrishna marked this conversation as resolved.
Show resolved Hide resolved
/// <returns><see cref="PurgeResult"/> object containing more information about the purged instance.</returns>
Task<PurgeResult> PurgeInstanceStateAsync(PurgeInstanceCondition purgeInstanceCondition);
}
}
53 changes: 53 additions & 0 deletions src/DurableTask.Core/PurgeInstanceCondition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// ----------------------------------------------------------------------------------
// 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;
using System.Collections.Generic;

/// <summary>
/// Class to hold conditions that should match to purge orchestration history
/// </summary>
public class PurgeInstanceCondition
shreyas-gopalakrishna marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// Constructor for purge instance conditions
/// </summary>
/// <param name="createdTimeFrom">CreatedTime of orchestrations. Purges history grater than this value.</param>
/// <param name="createdTimeTo">CreatedTime of orchestrations. Purges history less than this value.</param>
/// <param name="runtimeStatus">RuntimeStatus of orchestrations. You can specify several status.</param>
public PurgeInstanceCondition(DateTime createdTimeFrom, DateTime? createdTimeTo, IEnumerable<OrchestrationStatus> runtimeStatus)
{
this.CreatedTimeFrom = createdTimeFrom;
this.CreatedTimeTo = createdTimeTo;
this.RuntimeStatus = runtimeStatus;
}

/// <summary>
/// CreatedTime of orchestrations. Purges history grater than this value.
/// </summary>
public DateTime CreatedTimeFrom { get; set; }

/// <summary>
/// CreatedTime of orchestrations. Purges history less than this value.
/// </summary>
public DateTime? CreatedTimeTo { get; set; }

/// <summary>
/// RuntimeStatus of orchestrations
/// </summary>
public IEnumerable<OrchestrationStatus> RuntimeStatus { get; set; }

}
}
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 to hold statistics about this execution of purge history
/// </summary>
public class PurgeResult
{
/// <summary>
/// Constructor for purge history statistics
/// </summary>
/// <param name="instancesDeleted">Number of instances deleted</param>
public PurgeResult(int instancesDeleted)
{
this.InstancesDeleted = instancesDeleted;
}

/// <summary>
/// Number of instances deleted during this execution of purge history
/// </summary>
public int InstancesDeleted { get; }
}
}