forked from Azure/azure-webjobs-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctions.cs
78 lines (67 loc) · 2.7 KB
/
Functions.cs
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System.Threading.Tasks;
using Microsoft.Azure.EventHubs;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using SampleHost.Filters;
using SampleHost.Models;
namespace SampleHost
{
[ErrorHandler]
public class Functions
{
private readonly ISampleServiceA _sampleServiceA;
private readonly ISampleServiceB _sampleServiceB;
public Functions(ISampleServiceA sampleServiceA, ISampleServiceB sampleServiceB)
{
_sampleServiceA = sampleServiceA;
_sampleServiceB = sampleServiceB;
}
[Singleton]
public void BlobTrigger(
[BlobTrigger("test")] string blob, ILogger logger)
{
_sampleServiceB.DoIt();
logger.LogInformation("Processed blob: " + blob);
}
public void BlobPoisonBlobHandler(
[QueueTrigger("webjobs-blobtrigger-poison")] JObject blobInfo, ILogger logger)
{
string container = (string)blobInfo["ContainerName"];
string blobName = (string)blobInfo["BlobName"];
logger.LogInformation($"Poison blob: {container}/{blobName}");
}
[WorkItemValidator]
public void ProcessWorkItem(
[QueueTrigger("test")] WorkItem workItem, ILogger logger)
{
_sampleServiceA.DoIt();
logger.LogInformation($"Processed work item {workItem.ID}");
}
public async Task ProcessWorkItem_ServiceBus(
[ServiceBusTrigger("test-items")] WorkItem item,
string messageId,
int deliveryCount,
ILogger log)
{
log.LogInformation($"Processing ServiceBus message (Id={messageId}, DeliveryCount={deliveryCount})");
await Task.Delay(1000);
log.LogInformation($"Message complete (Id={messageId})");
}
/// <summary>
/// If there is an error during function invocation, function execution will be retried up to 3 times waiting for "00:00:20" between each retry
/// </summary>
/// <param name="events"></param>
/// <param name="log"></param>
[FixedDelayRetry(3, "00:00:03")]
public void ProcessEvents([EventHubTrigger("testhub2", Connection = "TestEventHubConnection")] EventData[] events, ILogger log)
{
foreach (var evt in events)
{
log.LogInformation($"Event processed (Offset={evt.SystemProperties.Offset}, SequenceNumber={evt.SystemProperties.SequenceNumber})");
}
}
}
}