-
Notifications
You must be signed in to change notification settings - Fork 182
/
WorkerOptions.cs
85 lines (76 loc) · 3.71 KB
/
WorkerOptions.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
79
80
81
82
83
84
85
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Text.Json;
using Azure.Core.Serialization;
using Microsoft.Azure.Functions.Worker.Diagnostics;
namespace Microsoft.Azure.Functions.Worker
{
/// <summary>
/// An options class for configuring the worker.
/// </summary>
public class WorkerOptions
{
/// <summary>
/// The <see cref="ObjectSerializer"/> to use for all JSON serialization and deserialization. By default,
/// this is a default <see cref="JsonObjectSerializer"/> with default <see cref="JsonSerializerOptions"/>.
/// </summary>
public ObjectSerializer? Serializer { get; set; }
/// <summary>
/// Gets the collection of input converters.
/// </summary>
public InputConverterCollection InputConverters { get; } = new InputConverterCollection();
/// <summary>
/// Gets the optional worker capabilities.
/// </summary>
public IDictionary<string, string> Capabilities { get; } = new Dictionary<string, string>()
{
// Enable these by default, although they are not strictly required and can be removed
{ "HandlesWorkerTerminateMessage", bool.TrueString },
{ "HandlesInvocationCancelMessage", bool.TrueString }
};
/// <summary>
/// Gets and sets the flag for opting in to unwrapping user-code-thrown
/// exceptions when they are surfaced to the Host.
/// </summary>
public bool EnableUserCodeException
{
get => GetBoolCapability(nameof(EnableUserCodeException));
set => SetBoolCapability(nameof(EnableUserCodeException), value);
}
/// <summary>
/// Gets or sets a value that determines if empty entries should be included in the function trigger message payload.
/// For example, if a set of entries were sent to a messaging service such as Service Bus or Event Hub and your function
/// app has a Service bus trigger or Event hub trigger, only the non-empty entries from the payload will be sent to the
/// function code as trigger data when this setting value is <see langword="false"/>. When it is <see langword="true"/>,
/// All entries will be sent to the function code as it is. Default value for this setting is <see langword="false"/>.
/// </summary>
public bool IncludeEmptyEntriesInMessagePayload
{
get => GetBoolCapability(nameof(IncludeEmptyEntriesInMessagePayload));
set => SetBoolCapability(nameof(IncludeEmptyEntriesInMessagePayload), value);
}
/// <summary>
/// Gets or sets a value that determines the schema to use when generating Activities. Currently internal as there is only
/// one schema, but stubbing this out for future use.
/// </summary>
internal OpenTelemetrySchemaVersion OpenTelemetrySchemaVersion { get; set; } = OpenTelemetrySchemaVersion.v1_17_0;
private bool GetBoolCapability(string name)
{
return Capabilities.TryGetValue(name, out string? value) && bool.TryParse(value, out bool b) && b;
}
// For false values, the host does not expect the capability to exist; there are some cases where this
// will be interpreted as "true" just because the key is there.
private void SetBoolCapability(string name, bool value)
{
if (value)
{
Capabilities[name] = bool.TrueString;
}
else
{
Capabilities.Remove(name);
}
}
}
}