forked from Azure/azure-functions-durable-extension
-
Notifications
You must be signed in to change notification settings - Fork 1
/
HttpSyncStart.fs
37 lines (29 loc) · 1.38 KB
/
HttpSyncStart.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
namespace VSSample
open System
open System.Net.Http
open Microsoft.Azure.WebJobs
open Microsoft.Azure.WebJobs.Extensions.Http
open Microsoft.Extensions.Logging
open FSharp.Control.Tasks
module HttpSyncStart =
let private getTimeSpan (request: HttpRequestMessage) (queryParameterName: string) (defaultSeconds: double) =
request.RequestUri.ParseQueryString().[queryParameterName]
|> Option.ofObj
|> Option.map Double.Parse
|> Option.defaultValue defaultSeconds
|> TimeSpan.FromSeconds
[<FunctionName("HttpSyncStart")>]
let Run([<HttpTrigger(AuthorizationLevel.Function, "post", Route = "orchestrators/{functionName}/wait")>] req: HttpRequestMessage,
[<OrchestrationClient>] starter: DurableOrchestrationClient,
functionName: string,
log: ILogger) =
task {
let! eventData = req.Content.ReadAsAsync<Object>()
let! instanceId = starter.StartNewAsync(functionName, eventData)
log.LogInformation(sprintf "Started orchestration with ID = '{%s}'." instanceId)
let timeout = getTimeSpan req "timeout" 30.0
let retryInterval = getTimeSpan req "retryInterval" 1.0
return! starter.WaitForCompletionOrCreateCheckStatusResponseAsync(req, instanceId, timeout, retryInterval)
}