-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
044d234
commit 4e6b170
Showing
20 changed files
with
873 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
src/WebJobs.Extensions.DurableTask/EventSourcedDurabilityProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using DurableTask.Core; | ||
using DurableTask.EventSourced; | ||
using Newtonsoft.Json; | ||
|
||
namespace Microsoft.Azure.WebJobs.Extensions.DurableTask | ||
{ | ||
internal class EventSourcedDurabilityProvider : DurabilityProvider | ||
{ | ||
private readonly EventSourcedOrchestrationService serviceClient; | ||
|
||
internal EventSourcedDurabilityProvider(EventSourcedOrchestrationService service, EventSourcedOrchestrationServiceSettings settings) | ||
: base("EventSourced", service, service, "StorageConnectionString") | ||
{ | ||
this.serviceClient = service; | ||
this.Settings = settings; | ||
} | ||
|
||
public EventSourcedOrchestrationServiceSettings Settings { get; private set; } | ||
|
||
public override bool SupportsEntities => true; | ||
|
||
public override bool SupportsPollFreeWait => true; | ||
|
||
public override bool GuaranteesOrderedDelivery => true; | ||
|
||
public override TimeSpan MaximumDelayTime { get; set; } = TimeSpan.MaxValue; | ||
|
||
/// <summary> | ||
/// The app setting containing the Azure Storage connection string. | ||
/// </summary> | ||
public override string ConnectionName => "StorageConnectionString"; // TODO this needs to be refactored to work across providers | ||
|
||
/// <inheritdoc/> | ||
public override async Task StopAsync(bool isForced) | ||
{ | ||
if (!this.Settings.KeepServiceRunning) | ||
{ | ||
await this.serviceClient.StopAsync(isForced); | ||
EventSourcedDurabilityProviderFactory.RemoveDurabilityProvider(this); | ||
} | ||
else | ||
{ | ||
await this.PurgeHistoryByFilters(default, default, null); | ||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
public async override Task<string> RetrieveSerializedEntityState(EntityId entityId, JsonSerializerSettings serializerSettings) | ||
{ | ||
var instanceId = EntityId.GetSchedulerIdFromEntityId(entityId); | ||
OrchestrationState state = await this.serviceClient.GetOrchestrationStateAsync(instanceId, true, true); | ||
|
||
if (state != null | ||
&& state.OrchestrationInstance != null | ||
&& state.Input != null) | ||
{ | ||
var schedulerState = JsonConvert.DeserializeObject<SchedulerState>(state.Input, serializerSettings); | ||
|
||
if (schedulerState.EntityExists) | ||
{ | ||
return schedulerState.EntityState; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public async override Task<IList<OrchestrationState>> GetOrchestrationStateWithInputsAsync(string instanceId, bool showInput = true) | ||
{ | ||
var result = new List<OrchestrationState>(); | ||
var state = await this.serviceClient.GetOrchestrationStateAsync(instanceId, showInput, true); | ||
if (state != null) | ||
{ | ||
result.Add(state); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public async override Task<PurgeHistoryResult> PurgeInstanceHistoryByInstanceId(string instanceId) | ||
{ | ||
var numberInstancesDeleted = await this.serviceClient.PurgeInstanceHistoryAsync(instanceId); | ||
return new PurgeHistoryResult(numberInstancesDeleted); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override Task<int> PurgeHistoryByFilters(DateTime createdTimeFrom, DateTime? createdTimeTo, IEnumerable<OrchestrationStatus> runtimeStatus) | ||
{ | ||
return this.serviceClient.PurgeInstanceHistoryAsync(createdTimeFrom, createdTimeTo, runtimeStatus); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public async override Task<OrchestrationStatusQueryResult> GetOrchestrationStateWithPagination(OrchestrationStatusQueryCondition condition, CancellationToken cancellationToken) | ||
{ | ||
var instanceQuery = new InstanceQuery( | ||
runtimeStatus: condition.RuntimeStatus?.Select(p => (OrchestrationStatus)Enum.Parse(typeof(OrchestrationStatus), p.ToString())).ToArray(), | ||
createdTimeFrom: (condition.CreatedTimeFrom == default) ? (DateTime?)null : condition.CreatedTimeFrom.ToUniversalTime(), | ||
createdTimeTo: (condition.CreatedTimeTo == default) ? (DateTime?)null : condition.CreatedTimeTo.ToUniversalTime(), | ||
instanceIdPrefix: condition.InstanceIdPrefix, | ||
fetchInput: condition.ShowInput); | ||
|
||
InstanceQueryResult result = await this.serviceClient.QueryOrchestrationStatesAsync(instanceQuery, condition.PageSize, condition.ContinuationToken, cancellationToken); | ||
|
||
return new OrchestrationStatusQueryResult() | ||
{ | ||
DurableOrchestrationState = result.Instances.Select(ostate => DurableClient.ConvertOrchestrationStateToStatus(ostate)).ToList(), | ||
ContinuationToken = result.ContinuationToken, | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.