-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpAttemptCounterEntityClient.cs
More file actions
41 lines (37 loc) · 1.75 KB
/
HttpAttemptCounterEntityClient.cs
File metadata and controls
41 lines (37 loc) · 1.75 KB
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
38
39
40
41
using FunctionApp.Entities;
using FunctionApp.Models;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System.Net.Http;
using System.Threading.Tasks;
namespace FunctionApp.Clients
{
public class HttpAttemptCounterEntityClient
{
/// <summary>
/// Returns the latest commited entity state for the given instanceid. Expects GET request /api/HttpAttemptCounterEntityClient?instanceid=[instanceidhere]
/// </summary>
/// <param name="req">HttpRequestMessage.</param>
/// <param name="client">IDurableEntityClient.</param>
/// <param name="log">ILogger.</param>
/// <returns>The latest commmited AttemptCounterEntityState for the given orchestration instance id.</returns>
[FunctionName(nameof(HttpAttemptCounterEntityClient))]
public static async Task<AttemptsEntityState> HttpAttemptCounterEntity(
[HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestMessage req,
[DurableClient] IDurableEntityClient client,
ILogger log)
{
// Get insanceId from input payload
var queryString = req.RequestUri.ParseQueryString();
var instanceId = queryString["instanceid"];
// Setup entity ID key'd from the orchestration instance id. One counter per orchestration instance.
var attemptCounterEntityId = new EntityId(nameof(AttemptsEntity), instanceId);
// get entity state
var stateResponse = await client.ReadEntityStateAsync<AttemptsEntityState>(attemptCounterEntityId);
// Return
return stateResponse.EntityState;
}
}
}