Skip to content

Commit 0570344

Browse files
Ongoing NuGet issues
1 parent 758330a commit 0570344

File tree

6 files changed

+110
-125
lines changed

6 files changed

+110
-125
lines changed

examples/bank-account/RetailBank.AzureFunctionApp/Account/Functions/AccountFunctions.BulkDataFunctions.cs

Lines changed: 0 additions & 122 deletions
This file was deleted.

examples/bank-account/RetailBank.AzureFunctionApp/Account/Functions/AccountFunctions.DurableFunctions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ public static async Task<Tuple<string, bool>> AccrueInterestForSpecificAccount
162162
[FunctionName(nameof(ApplyInterestForAllAccountsTrigger))]
163163
public static async Task ApplyInterestForAllAccountsTrigger(
164164
[HttpTrigger(AuthorizationLevel.Function, "POST", Route = @"ApplyInterestForAllAccounts")]HttpRequestMessage req,
165-
[DurableClient] IDurableOrchestrationClient accrueInterestOrchestration)
165+
[DurableClient] IDurableOrchestrationClient applyInterestOrchestration)
166166
{
167167

168168
// Get all the account numbers
169169
IEnumerable<string> allAccounts = await req.Content.ReadAsAsync<IEnumerable<string>>();
170170

171-
await accrueInterestOrchestration.StartNewAsync(nameof(ApplyInterestForAllAccounts), allAccounts);
171+
await applyInterestOrchestration.StartNewAsync(nameof(ApplyInterestForAllAccounts), allAccounts);
172172

173173
}
174174

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<Authors>Duncan Jones</Authors>
6+
<Description>Utility functions for using Azure Durable Functions in concert with the EventSourcingOnAzureFunctions library</Description>
7+
<PackageProjectUrl>https://github.com/MerrionComputing/EventsSourcing-on-Azure-Functions</PackageProjectUrl>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.4.1" />
12+
<PackageReference Include="System.Threading.Tasks.Parallel" Version="4.3.0" />
13+
</ItemGroup>
14+
15+
</Project>

src/DurableFunctionsUtility/FanOut.cs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
7+
8+
namespace DurableFunctionsUtility
9+
{
10+
public static class FanOut
11+
{
12+
13+
14+
public static int THROTTLE_BATCH_SIZE = 200;
15+
16+
/// <summary>
17+
/// Run a throttled fan out of the named orchestration passing in each of the
18+
/// unique keys for it to run over
19+
/// </summary>
20+
/// <param name="client">
21+
/// The durable orchestration instance to run the fan-out over
22+
/// </param>
23+
/// <param name="orchestrationName">
24+
/// The name of the function to run
25+
/// </param>
26+
/// <param name="keys">
27+
/// The unique keys to pass in to the instances of the orchestration
28+
/// </param>
29+
/// <returns>
30+
/// An awaitable task that performs the fan-out
31+
/// </returns>
32+
public static async Task ThrottledFanOut(IDurableOrchestrationClient client,
33+
string orchestrationName,
34+
IEnumerable<string> keys)
35+
{
36+
if (keys != null)
37+
{
38+
await keys.ParallelForEachAsync(THROTTLE_BATCH_SIZE, key => {
39+
return client.StartNewAsync(orchestrationName, key);
40+
});
41+
}
42+
43+
return;
44+
}
45+
46+
47+
48+
public static async Task ParallelForEachAsync<T>(this IEnumerable<T> items, int maxConcurrency, Func<T, Task> action)
49+
{
50+
List<Task> tasks;
51+
if (items is ICollection<T> itemCollection)
52+
{
53+
// optimization to reduce the number of memory allocations
54+
tasks = new List<Task>(itemCollection.Count);
55+
}
56+
else
57+
{
58+
tasks = new List<Task>();
59+
}
60+
61+
using var semaphore = new SemaphoreSlim(maxConcurrency);
62+
foreach (T item in items)
63+
{
64+
tasks.Add(InvokeThrottledAction(item, action, semaphore));
65+
}
66+
67+
await Task.WhenAll(tasks);
68+
}
69+
70+
static async Task InvokeThrottledAction<T>(T item, Func<T, Task> action, SemaphoreSlim semaphore)
71+
{
72+
await semaphore.WaitAsync();
73+
try
74+
{
75+
await action(item);
76+
}
77+
finally
78+
{
79+
semaphore.Release();
80+
}
81+
}
82+
}
83+
}

src/EventSourcingOnAzureFunctions.Common/EventSourcingOnAzureFunctions.Common.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<PackageId>EventSourcingOnAzureFunctions.Common</PackageId>
66
<PackageVersion>1.1</PackageVersion>
77
<LangVersion>7.1</LangVersion>
8-
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
98
<Authors>Duncan Jones</Authors>
109
<Description>Common function library to provide for event sourcing backed state management in Azure serverless functions</Description>
1110
<PackageProjectUrl>https://github.com/MerrionComputing/EventsSourcing-on-Azure-Functions</PackageProjectUrl>

src/EventSourcingOnAzureFunctions.sln

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BankBranch.AzureFunctionApp
1313
EndProject
1414
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BankingProduct.AzureFunctionApp", "..\examples\bank-account\BankingProduct.AzureFunctionApp\BankingProduct.AzureFunctionApp.csproj", "{D1740ED2-DC7C-4258-90E7-7B7A473D1EBB}"
1515
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DurableFunctionsUtility", "DurableFunctionsUtility\DurableFunctionsUtility.csproj", "{383F8FDB-91B9-4E93-A4CD-A1BA85032919}"
17+
EndProject
1618
Global
1719
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1820
Debug|Any CPU = Debug|Any CPU
@@ -61,6 +63,14 @@ Global
6163
{D1740ED2-DC7C-4258-90E7-7B7A473D1EBB}.Release|Any CPU.Build.0 = Release|Any CPU
6264
{D1740ED2-DC7C-4258-90E7-7B7A473D1EBB}.Release|x64.ActiveCfg = Release|x64
6365
{D1740ED2-DC7C-4258-90E7-7B7A473D1EBB}.Release|x64.Build.0 = Release|x64
66+
{383F8FDB-91B9-4E93-A4CD-A1BA85032919}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
67+
{383F8FDB-91B9-4E93-A4CD-A1BA85032919}.Debug|Any CPU.Build.0 = Debug|Any CPU
68+
{383F8FDB-91B9-4E93-A4CD-A1BA85032919}.Debug|x64.ActiveCfg = Debug|Any CPU
69+
{383F8FDB-91B9-4E93-A4CD-A1BA85032919}.Debug|x64.Build.0 = Debug|Any CPU
70+
{383F8FDB-91B9-4E93-A4CD-A1BA85032919}.Release|Any CPU.ActiveCfg = Release|Any CPU
71+
{383F8FDB-91B9-4E93-A4CD-A1BA85032919}.Release|Any CPU.Build.0 = Release|Any CPU
72+
{383F8FDB-91B9-4E93-A4CD-A1BA85032919}.Release|x64.ActiveCfg = Release|Any CPU
73+
{383F8FDB-91B9-4E93-A4CD-A1BA85032919}.Release|x64.Build.0 = Release|Any CPU
6474
EndGlobalSection
6575
GlobalSection(SolutionProperties) = preSolution
6676
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)