Skip to content

Instantly share code, notes, and snippets.

View mikhailshilkov's full-sized avatar

Mikhail Shilkov mikhailshilkov

View GitHub Profile
// string -> Async<Match list>
let findMatchingGift (wish: string) = async {
// Call a custom machine learning model
// The real implementation uses the Customer profile to adjust decisions by age, etc.
// but we'll keep the model simple for now.
}
type Reservation =
{
Kid: Customer
Product: Product
}
type Match =
{
Product: Product
Confidence: Probability
}
type WishList =
{
Kid: Customer
Wishes: string list
}
using System;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Queue;
namespace sendQueue
{
var emailSendingTasks =
recepients
.Select(to => context.CallActivityAsync<bool>("SendEmail", to))
.ToArray();
var results = await Task.WhenAll(emailSendingTasks);
if (results.All(r => r)) { /* ... */ }
[FunctionName("ParallelWorkflow")]
public static async Task Parallel([OrchestrationTrigger] DurableOrchestrationContext context)
{
var amsterdam = context.CallSubOrchestratorAsync("BookTrip", serverlessDaysAmsterdam);
var hamburg = context.CallSubOrchestratorAsync("BookTrip", serverlessDaysHamburg);
var expenses = await Task.WhenAll(amsterdam, hamburg);
await context.CallActivityAsync("ReportExpenses", expenses);
}
[FunctionName("CombinedOrchestrator")]
public static async Task CombinedOrchestrator([OrchestrationTrigger] DurableOrchestrationContext context)
{
await context.CallSubOrchestratorAsync("BookTrip", serverlessDaysAmsterdam);
await context.CallSubOrchestratorAsync("BookTrip", serverlessDaysHamburg);
}
var options = new RetryOptions(
firstRetryInterval: TimeSpan.FromMinutes(1),
maxNumberOfAttempts: 5);
options.BackoffCoefficient = 2.0;
await context.CallActivityWithRetryAsync("BookFlight", options, itinerary);
[FunctionName("SequentialWorkflow")]
public static async Task Sequential([OrchestrationTrigger] DurableOrchestrationContext context)
{
var conf = await context.CallActivityAsync<ConfTicket>("BookConference", "ServerlessDays");
try
{
var itinerary = MakeItinerary(/* ... */);
await context.CallActivityAsync("BookFlight", itinerary);
}
catch (FunctionFailedException)