Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Azure Durable F#unctions

Azure Durable F#unctions

Serverless architecture is the future of the cloud. Initially, the serverless tech focused on running small isolated tasks in response to cloud events.

The next evolutionary step is to compose complex applications out of those small components. Azure Durable Functions provides powerful abstractions for workflow composition on top of standard Functions.

Join Mikhail, the author of DurableFunctions.FSharp library, to see how F# is the most powerful language to orchestrate stateful, reliable, long-running serverless applications.

Mikhail Shilkov

April 05, 2019
Tweet

More Decks by Mikhail Shilkov

Other Decks in Programming

Transcript

  1. $

  2. let trivial person = orchestrator { let text = sprintf

    "Hello %s" person do! Activity.call sendText text }
  3. let trivial person = orchestrator { let text = sprintf

    "Hello %s" person do! Activity.call sendText text } [<FunctionName("TrivialOrchestrator")>] let trivialOrchestrator( [<OrchestrationTrigger>] context: DurableOrchestrationContext) = Orchestrator.run (trivial, context)
  4. let trivial person = orchestrator { let text = sprintf

    "Hello %s" person do! Activity.call sendText text } [<FunctionName("TrivialOrchestrator")>] let trivialOrchestrator( [<OrchestrationTrigger>] context: DurableOrchestrationContext) = Orchestrator.run (trivial, context)
  5. let trivial person = orchestrator { let text = sprintf

    "Hello %s" person do! Activity.call sendText text } [<FunctionName("TrivialOrchestrator")>] let trivialOrchestrator( [<OrchestrationTrigger>] context: DurableOrchestrationContext) = Orchestrator.run (trivial, context)
  6. let raiseAlert alert = orchestrator { let! text = Activity.call

    sendText alert let! email = Activity.call sendEmail alert let entry = AlertEntry.make alert text email do! Activity.call recordAlert entry }
  7. 1. Orchestrator Started 2. ExecutionStarted: RaiseAlert 3. TaskScheduled: SendText 4.

    OrchestratorCompleted 5. TaskCompleted: "Text sent at 11:33" 6. OrchestratorStarted 7. TaskScheduled: SendEmail 8. OrchestratorCompleted 9. TaskCompleted: “Email sent at 11:35"
  8. let raiseAlert alert = orchestrator { let! text = Activity.call

    sendText alert let! email = Activity.call sendEmail alert let entry = AlertEntry.make alert text email do! Activity.call recordAlert entry }
  9. let errorHandling alert = orchestrator { let! text = Activity.call

    sendText alert let! email = try Activity.call sendEmail alert with | :? FunctionFailedException -> Activity.call sendEmailViaBackupChannel alert let entry = AlertEntry.make alert text email do! Activity.call recordAlert entry }
  10. let retries alert = orchestrator { let! text = Activity.call

    sendText alert let policy = ExponentialBackOff { FirstRetryInterval = minutes 1 BackoffCoefficient = 2.0 MaxNumberOfAttempts = 4 } let! email = Activity.callWithRetries policy sendEmail alert let entry = AlertEntry.make alert text email do! Activity.call recordAlert entry }
  11. let fanOut alert = orchestrator { let textCall = Activity.call

    sendText alert let emailCall = Activity.call sendEmail alert let! text = textCall let! email = emailCall let entry = AlertEntry.make alert text email do! Activity.call recordAlert entry }
  12. let fanOut alerts = orchestrator { let! emails = alerts

    |> List.map (Activity.call sendEmail) |> Activity.all // ... }
  13. let schedule alert = orchestrator { let! email = Activity.call

    sendEmail alert do! Orchestrator.delay (minutes 10) let! isResolved = Activity.call checkStatus alert if (not isResolved) then do! Activity.call sendText alert let! result = Orchestrator.waitForEvent (hours 1) "Ack" match result with | Ok r -> // Acknowledged ... | Error _ -> // Escalate ... }
  14. let schedule alert = orchestrator { let! email = Activity.call

    sendEmail alert do! Orchestrator.delay (minutes 10) let! isResolved = Activity.call checkStatus alert if (not isResolved) then do! Activity.call sendText alert let! result = Orchestrator.waitForEvent (hours 1) "Ack" match result with | Ok r -> // Acknowledged ... | Error _ -> // Escalate ... }
  15. let schedule alert = orchestrator { let! email = Activity.call

    sendEmail alert do! Orchestrator.delay (minutes 10) let! isResolved = Activity.call checkStatus alert if (not isResolved) then do! Activity.call sendText alert let! result = Orchestrator.waitForEvent (hours 1) "Ack" match result with | Ok r -> // Acknowledged ... | Error _ -> // Escalate ... }
  16. let schedule alert = orchestrator { let! email = Activity.call

    sendEmail alert do! Orchestrator.delay (minutes 10) let! isResolved = Activity.call checkStatus alert if (not isResolved) then do! Activity.call sendText alert let! result = Orchestrator.waitForEvent (hours 1) "Ack" match result with | Ok r -> // Acknowledged ... | Error _ -> // Escalate ... }