Skip to content

Commit 41f2d77

Browse files
Add durability-provider-specific support for implicit entity deletion. (#2251)
1 parent 575772b commit 41f2d77

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/WebJobs.Extensions.DurableTask/DurabilityProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public DurabilityProvider(string storageProviderName, IOrchestrationService serv
7676
/// </summary>
7777
public virtual bool GuaranteesOrderedDelivery => false;
7878

79+
/// <summary>
80+
/// Specifies whether this backend supports implicit deletion of entities.
81+
/// </summary>
82+
public virtual bool SupportsImplicitEntityDeletion => false;
83+
7984
/// <summary>
8085
/// JSON representation of configuration to emit in telemetry.
8186
/// </summary>

src/WebJobs.Extensions.DurableTask/DurableTaskExtension.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ public string HubName
258258
internal TimeSpan MessageReorderWindow
259259
=> this.defaultDurabilityProvider.GuaranteesOrderedDelivery ? TimeSpan.Zero : TimeSpan.FromMinutes(this.Options.EntityMessageReorderWindowInMinutes);
260260

261+
internal bool UseImplicitEntityDeletion => this.defaultDurabilityProvider.SupportsImplicitEntityDeletion;
262+
261263
internal IApplicationLifetimeWrapper HostLifetimeService { get; } = HostLifecycleService.NoOp;
262264

263265
internal OutOfProcOrchestrationProtocol OutOfProcProtocol { get; }

src/WebJobs.Extensions.DurableTask/Listener/TaskEntityShim.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ internal void Rehydrate(string serializedInput)
147147
{
148148
if (serializedInput == null)
149149
{
150-
// this instance was automatically started by DTFx
150+
// this instance was automatically started by DTFx, or a previous execution called continueAsNew(null)
151151
this.context.State = new SchedulerState();
152152
}
153153
else
@@ -247,10 +247,18 @@ public override async Task<string> Execute(OrchestrationContext innerContext, st
247247
this.context.State.Suspended = true;
248248
}
249249

250-
var jstate = JToken.FromObject(this.context.State);
251-
252-
// continue as new
253-
innerContext.ContinueAsNew(jstate);
250+
if (this.Config.UseImplicitEntityDeletion && this.context.State.IsEmpty)
251+
{
252+
// this entity scheduler is idle and the entity is deleted, so the instance and history can be removed from storage
253+
// we convey this to the durability provider by issuing a continue-as-new with null input
254+
innerContext.ContinueAsNew(null);
255+
}
256+
else
257+
{
258+
// we persist the state of the entity scheduler and entity by issuing a continue-as-new
259+
var jstate = JToken.FromObject(this.context.State);
260+
innerContext.ContinueAsNew(jstate);
261+
}
254262
}
255263
}
256264
catch (Exception e)

0 commit comments

Comments
 (0)