|
1 | | -// Copyright (c) Microsoft Corporation. |
2 | | -// Licensed under the MIT License. |
3 | | - |
4 | | -namespace Microsoft.DurableTask; |
5 | | - |
6 | | -/// <summary> |
7 | | -/// Options that can be used to control the behavior of orchestrator task execution. |
8 | | -/// </summary> |
9 | | -public record TaskOptions |
10 | | -{ |
11 | | - /// <summary> |
12 | | - /// Initializes a new instance of the <see cref="TaskOptions"/> class. |
13 | | - /// </summary> |
14 | | - /// <param name="retry">The task retry options.</param> |
15 | | - public TaskOptions(TaskRetryOptions? retry = null) |
16 | | - { |
17 | | - this.Retry = retry; |
18 | | - } |
19 | | - |
20 | | - /// <summary> |
21 | | - /// Gets the task retry options. |
22 | | - /// </summary> |
23 | | - public TaskRetryOptions? Retry { get; init; } |
24 | | - |
25 | | - /// <summary> |
26 | | - /// Returns a new <see cref="TaskOptions" /> from the provided <see cref="RetryPolicy" />. |
27 | | - /// </summary> |
28 | | - /// <param name="policy">The policy to convert from.</param> |
29 | | - /// <returns>A <see cref="TaskOptions" /> built from the policy.</returns> |
30 | | - public static TaskOptions FromRetryPolicy(RetryPolicy policy) => new(policy); |
31 | | - |
32 | | - /// <summary> |
33 | | - /// Returns a new <see cref="TaskOptions" /> from the provided <see cref="AsyncRetryHandler" />. |
34 | | - /// </summary> |
35 | | - /// <param name="handler">The handler to convert from.</param> |
36 | | - /// <returns>A <see cref="TaskOptions" /> built from the handler.</returns> |
37 | | - public static TaskOptions FromRetryHandler(AsyncRetryHandler handler) => new(handler); |
38 | | - |
39 | | - /// <summary> |
40 | | - /// Returns a new <see cref="TaskOptions" /> from the provided <see cref="RetryHandler" />. |
41 | | - /// </summary> |
42 | | - /// <param name="handler">The handler to convert from.</param> |
43 | | - /// <returns>A <see cref="TaskOptions" /> built from the handler.</returns> |
44 | | - public static TaskOptions FromRetryHandler(RetryHandler handler) => new(handler); |
45 | | - |
46 | | - /// <summary> |
47 | | - /// Returns a new <see cref="SubOrchestrationOptions" /> with the provided instance ID. This can be used when |
48 | | - /// starting a new sub-orchestration to specify the instance ID. |
49 | | - /// </summary> |
50 | | - /// <param name="instanceId">The instance ID to use.</param> |
51 | | - /// <returns>A new <see cref="SubOrchestrationOptions" />.</returns> |
52 | | - public SubOrchestrationOptions WithInstanceId(string instanceId) => new(this, instanceId); |
53 | | -} |
54 | | - |
55 | | -/// <summary> |
56 | | -/// Options that can be used to control the behavior of orchestrator task execution. This derived type can be used to |
57 | | -/// supply extra options for orchestrations. |
58 | | -/// </summary> |
59 | | -public record SubOrchestrationOptions : TaskOptions |
60 | | -{ |
61 | | - /// <summary> |
62 | | - /// Initializes a new instance of the <see cref="SubOrchestrationOptions"/> class. |
63 | | - /// </summary> |
64 | | - /// <param name="retry">The task retry options.</param> |
65 | | - /// <param name="instanceId">The orchestration instance ID.</param> |
66 | | - public SubOrchestrationOptions(TaskRetryOptions? retry = null, string? instanceId = null) |
67 | | - : base(retry) |
68 | | - { |
69 | | - this.InstanceId = instanceId; |
70 | | - } |
71 | | - |
72 | | - /// <summary> |
73 | | - /// Initializes a new instance of the <see cref="SubOrchestrationOptions"/> class. |
74 | | - /// </summary> |
75 | | - /// <param name="options">The task options to wrap.</param> |
76 | | - /// <param name="instanceId">The orchestration instance ID.</param> |
77 | | - public SubOrchestrationOptions(TaskOptions options, string? instanceId = null) |
78 | | - : base(options) |
79 | | - { |
80 | | - this.InstanceId = instanceId; |
81 | | - if (instanceId is null && options is SubOrchestrationOptions derived) |
82 | | - { |
83 | | - this.InstanceId = derived.InstanceId; |
84 | | - } |
85 | | - } |
86 | | - |
87 | | - /// <summary> |
88 | | - /// Gets the orchestration instance ID. |
89 | | - /// </summary> |
90 | | - public string? InstanceId { get; init; } |
91 | | -} |
92 | | - |
93 | | -/// <summary> |
94 | | -/// Options for submitting new orchestrations via the client. |
95 | | -/// </summary> |
96 | | -/// <param name="InstanceId"> |
97 | | -/// The unique ID of the orchestration instance to schedule. If not specified, a new GUID value is used. |
98 | | -/// </param> |
99 | | -/// <param name="StartAt"> |
100 | | -/// The time when the orchestration instance should start executing. If not specified or if a date-time in the past |
101 | | -/// is specified, the orchestration instance will be scheduled immediately. |
102 | | -/// </param> |
103 | | -public record StartOrchestrationOptions(string? InstanceId = null, DateTimeOffset? StartAt = null); |
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +using System.Collections.Immutable; |
| 5 | + |
| 6 | +namespace Microsoft.DurableTask; |
| 7 | + |
| 8 | +/// <summary> |
| 9 | +/// Options that can be used to control the behavior of orchestrator task execution. |
| 10 | +/// </summary> |
| 11 | +public record TaskOptions |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// Initializes a new instance of the <see cref="TaskOptions"/> class. |
| 15 | + /// </summary> |
| 16 | + /// <param name="retry">The task retry options.</param> |
| 17 | + public TaskOptions(TaskRetryOptions? retry = null) |
| 18 | + { |
| 19 | + this.Retry = retry; |
| 20 | + } |
| 21 | + |
| 22 | + /// <summary> |
| 23 | + /// Gets the task retry options. |
| 24 | + /// </summary> |
| 25 | + public TaskRetryOptions? Retry { get; init; } |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// Returns a new <see cref="TaskOptions" /> from the provided <see cref="RetryPolicy" />. |
| 29 | + /// </summary> |
| 30 | + /// <param name="policy">The policy to convert from.</param> |
| 31 | + /// <returns>A <see cref="TaskOptions" /> built from the policy.</returns> |
| 32 | + public static TaskOptions FromRetryPolicy(RetryPolicy policy) => new(policy); |
| 33 | + |
| 34 | + /// <summary> |
| 35 | + /// Returns a new <see cref="TaskOptions" /> from the provided <see cref="AsyncRetryHandler" />. |
| 36 | + /// </summary> |
| 37 | + /// <param name="handler">The handler to convert from.</param> |
| 38 | + /// <returns>A <see cref="TaskOptions" /> built from the handler.</returns> |
| 39 | + public static TaskOptions FromRetryHandler(AsyncRetryHandler handler) => new(handler); |
| 40 | + |
| 41 | + /// <summary> |
| 42 | + /// Returns a new <see cref="TaskOptions" /> from the provided <see cref="RetryHandler" />. |
| 43 | + /// </summary> |
| 44 | + /// <param name="handler">The handler to convert from.</param> |
| 45 | + /// <returns>A <see cref="TaskOptions" /> built from the handler.</returns> |
| 46 | + public static TaskOptions FromRetryHandler(RetryHandler handler) => new(handler); |
| 47 | + |
| 48 | + /// <summary> |
| 49 | + /// Returns a new <see cref="SubOrchestrationOptions" /> with the provided instance ID. This can be used when |
| 50 | + /// starting a new sub-orchestration to specify the instance ID. |
| 51 | + /// </summary> |
| 52 | + /// <param name="instanceId">The instance ID to use.</param> |
| 53 | + /// <returns>A new <see cref="SubOrchestrationOptions" />.</returns> |
| 54 | + public SubOrchestrationOptions WithInstanceId(string instanceId) => new(this, instanceId); |
| 55 | +} |
| 56 | + |
| 57 | +/// <summary> |
| 58 | +/// Options that can be used to control the behavior of orchestrator task execution. This derived type can be used to |
| 59 | +/// supply extra options for orchestrations. |
| 60 | +/// </summary> |
| 61 | +public record SubOrchestrationOptions : TaskOptions |
| 62 | +{ |
| 63 | + /// <summary> |
| 64 | + /// Initializes a new instance of the <see cref="SubOrchestrationOptions"/> class. |
| 65 | + /// </summary> |
| 66 | + /// <param name="retry">The task retry options.</param> |
| 67 | + /// <param name="instanceId">The orchestration instance ID.</param> |
| 68 | + public SubOrchestrationOptions(TaskRetryOptions? retry = null, string? instanceId = null) |
| 69 | + : base(retry) |
| 70 | + { |
| 71 | + this.InstanceId = instanceId; |
| 72 | + } |
| 73 | + |
| 74 | + /// <summary> |
| 75 | + /// Initializes a new instance of the <see cref="SubOrchestrationOptions"/> class. |
| 76 | + /// </summary> |
| 77 | + /// <param name="options">The task options to wrap.</param> |
| 78 | + /// <param name="instanceId">The orchestration instance ID.</param> |
| 79 | + public SubOrchestrationOptions(TaskOptions options, string? instanceId = null) |
| 80 | + : base(options) |
| 81 | + { |
| 82 | + this.InstanceId = instanceId; |
| 83 | + if (instanceId is null && options is SubOrchestrationOptions derived) |
| 84 | + { |
| 85 | + this.InstanceId = derived.InstanceId; |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + /// <summary> |
| 90 | + /// Gets the orchestration instance ID. |
| 91 | + /// </summary> |
| 92 | + public string? InstanceId { get; init; } |
| 93 | +} |
| 94 | + |
| 95 | +/// <summary> |
| 96 | +/// Options for submitting new orchestrations via the client. |
| 97 | +/// </summary> |
| 98 | +/// <param name="InstanceId"> |
| 99 | +/// The unique ID of the orchestration instance to schedule. If not specified, a new GUID value is used. |
| 100 | +/// </param> |
| 101 | +/// <param name="StartAt"> |
| 102 | +/// The time when the orchestration instance should start executing. If not specified or if a date-time in the past |
| 103 | +/// is specified, the orchestration instance will be scheduled immediately. |
| 104 | +/// </param> |
| 105 | +public record StartOrchestrationOptions(string? InstanceId = null, DateTimeOffset? StartAt = null) |
| 106 | +{ |
| 107 | + /// <summary> |
| 108 | + /// Gets the tags to associate with the orchestration instance. |
| 109 | + /// </summary> |
| 110 | + public IReadOnlyDictionary<string, string> Tags { get; init; } = ImmutableDictionary.Create<string, string>(); |
| 111 | +} |
0 commit comments