Skip to content

Commit ffaa2dc

Browse files
Allow stopping 'eternal' orchestrations
1 parent da7ade2 commit ffaa2dc

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

‎samples/Eternal.fs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ let printTime =
99
|> Activity.define "PrintTime"
1010

1111
let workflow = orchestrator {
12-
let! _ = Activity.call printTime DateTime.Now
12+
let! s = Activity.call printTime DateTime.Now
1313
do! Orchestrator.delay (TimeSpan.FromSeconds 5.0)
14+
return if s.Contains "00" then Stop else ContinueAsNew ()
1415
}
1516

1617
[<FunctionName("PrintTime")>]

‎src/DurableFunctions.FSharp/Orchestrator.fs‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ open System.Threading.Tasks
66
open Microsoft.Azure.WebJobs
77
open OrchestratorBuilder
88

9+
type EternalOrchestrationCommand<'a> = Stop | ContinueAsNew of 'a
10+
911
type Orchestrator = class
1012

1113
/// Runs a workflow which expects an input parameter by reading this parameter from
@@ -19,12 +21,24 @@ type Orchestrator = class
1921
let input = context.GetInput<'a> ()
2022
workflow input context
2123

22-
static member runEternal (workflow : ContextTask<'b>, context : DurableOrchestrationContext) : Task<'b> =
24+
static member runEternal (workflow : ContextTask<EternalOrchestrationCommand<unit>>, context : DurableOrchestrationContext) : Task =
2325
let task = workflow context
2426
task.ContinueWith (
25-
fun (t: Task<'b>) ->
26-
context.ContinueAsNew null
27-
t.Result)
27+
fun (t: Task<EternalOrchestrationCommand<unit>>) ->
28+
match t.Result with
29+
| ContinueAsNew () -> context.ContinueAsNew null
30+
| Stop -> ()
31+
)
32+
33+
static member runEternal (workflow : 'a -> ContextTask<EternalOrchestrationCommand<'a>>, context : DurableOrchestrationContext) : Task =
34+
let input = context.GetInput<'a> ()
35+
let task = workflow input context
36+
task.ContinueWith (
37+
fun (t: Task<EternalOrchestrationCommand<'a>>) ->
38+
match t.Result with
39+
| ContinueAsNew r -> context.ContinueAsNew r
40+
| Stop -> ()
41+
)
2842

2943
/// Returns a fixed value as a orchestrator.
3044
static member ret value (_: DurableOrchestrationContext) =

0 commit comments

Comments
 (0)