|
| 1 | +module FSharp.DurableExtensions |
| 2 | + |
| 3 | +open System.Threading.Tasks |
| 4 | +open Microsoft.FSharp.Quotations |
| 5 | +open Microsoft.Azure.WebJobs.Extensions.DurableTask |
| 6 | + |
| 7 | +/// Extension methods for calling Azure Durable Activity Functions with strongly typed inputs and outputs. |
| 8 | +type IDurableOrchestrationContext with |
| 9 | + |
| 10 | + /// Calls a function with no ActivityTrigger input. |
| 11 | + member ctx.CallActivity<'D1, 'Output> ([<ReflectedDefinition>] azureFn: Expr<'D1 -> Task<'Output>>, ?retry: RetryOptions) : Task<'Output> = |
| 12 | + let functionName = |
| 13 | + match azureFn with |
| 14 | + | DerivedPatterns.Lambdas(_, Patterns.Call(_,mi,_)) -> mi.Name |
| 15 | + | _ -> failwith "Invalid fn" |
| 16 | + |
| 17 | + match retry with |
| 18 | + | Some opt -> |
| 19 | + ctx.CallActivityWithRetryAsync<'Output>(functionName, opt, null) |
| 20 | + | None -> |
| 21 | + ctx.CallActivityAsync<'Output>(functionName, null) |
| 22 | + |
| 23 | + /// Calls a function with an ActivityTrigger input parameter and no dependency parameters. |
| 24 | + member ctx.CallActivity<'Input, 'Output> ([<ReflectedDefinition>] azureFn: Expr<'Input -> Task<'Output>>, req: 'Input, ?retry: RetryOptions) : Task<'Output> = |
| 25 | + let functionName = |
| 26 | + match azureFn with |
| 27 | + | DerivedPatterns.Lambdas(_, Patterns.Call(_,mi,_)) -> mi.Name |
| 28 | + | _ -> failwith "Invalid fn" |
| 29 | + |
| 30 | + match retry with |
| 31 | + | Some opt -> |
| 32 | + ctx.CallActivityWithRetryAsync<'Output>(functionName, opt, req) |
| 33 | + | None -> |
| 34 | + ctx.CallActivityAsync<'Output>(functionName, req) |
| 35 | + |
| 36 | + /// Calls a function with an ActivityTrigger input parameter and one dependency parameter. |
| 37 | + member ctx.CallActivity<'Input, 'D1, 'Output> ([<ReflectedDefinition>] azureFn: Expr<'Input * 'D1 -> Task<'Output>>, req: 'Input, ?retry: RetryOptions) : Task<'Output> = |
| 38 | + let functionName = |
| 39 | + match azureFn with |
| 40 | + | DerivedPatterns.Lambdas(_, Patterns.Call(_,mi,_)) -> mi.Name |
| 41 | + | _ -> failwith "Invalid fn" |
| 42 | + |
| 43 | + match retry with |
| 44 | + | Some opt -> |
| 45 | + ctx.CallActivityWithRetryAsync<'Output>(functionName, opt, req) |
| 46 | + | None -> |
| 47 | + ctx.CallActivityAsync<'Output>(functionName, req) |
| 48 | + |
| 49 | + /// Calls a function with an ActivityTrigger input parameter and two dependency parameters. |
| 50 | + member ctx.CallActivity<'Input, 'D1, 'D2, 'Output> ([<ReflectedDefinition>] azureFn: Expr<'Input * 'D1 * 'D2 -> Task<'Output>>, req: 'Input, ?retry: RetryOptions) : Task<'Output> = |
| 51 | + let functionName = |
| 52 | + match azureFn with |
| 53 | + | DerivedPatterns.Lambdas(_, Patterns.Call(_,mi,_)) -> mi.Name |
| 54 | + | _ -> failwith "Invalid fn" |
| 55 | + |
| 56 | + match retry with |
| 57 | + | Some opt -> |
| 58 | + ctx.CallActivityWithRetryAsync<'Output>(functionName, opt, req) |
| 59 | + | None -> |
| 60 | + ctx.CallActivityAsync<'Output>(functionName, req) |
| 61 | + |
| 62 | + /// Calls a function with an ActivityTrigger input parameter and three dependency parameters. |
| 63 | + member ctx.CallActivity<'Input, 'D1, 'D2, 'D3, 'Output> ([<ReflectedDefinition>] azureFn: Expr<'Input * 'D1 * 'D2 * 'D3 -> Task<'Output>>, req: 'Input, ?retry: RetryOptions) : Task<'Output> = |
| 64 | + let functionName = |
| 65 | + match azureFn with |
| 66 | + | DerivedPatterns.Lambdas(_, Patterns.Call(_,mi,_)) -> mi.Name |
| 67 | + | _ -> failwith "Invalid fn" |
| 68 | + |
| 69 | + match retry with |
| 70 | + | Some opt -> |
| 71 | + ctx.CallActivityWithRetryAsync<'Output>(functionName, opt, req) |
| 72 | + | None -> |
| 73 | + ctx.CallActivityAsync<'Output>(functionName, req) |
0 commit comments