/// <summary> /// Internal constructor. /// </summary> /// <param name="client">The associated client.</param> /// <param name="methodName"> /// Optionally identifies the target workflow method by the name specified in /// the <c>[WorkflowMethod]</c> attribute tagging the method. Pass a <c>null</c> /// or empty string to target the default method. /// </param> /// <param name="options">Optional workflow options.</param> internal WorkflowFutureStub(TemporalClient client, string methodName = null, StartWorkflowOptions options = null) { Covenant.Requires <ArgumentNullException>(client != null, nameof(client)); var workflowInterface = typeof(WorkflowInterface); var method = TemporalHelper.GetWorkflowMethod(workflowInterface, methodName); TemporalHelper.ValidateWorkflowInterface(workflowInterface); this.client = client; this.workflowTypeName = TemporalHelper.GetWorkflowTarget(workflowInterface, methodName).WorkflowTypeName; this.options = StartWorkflowOptions.Normalize(client, options, workflowInterface, method); }
/// <summary> /// Used to construct an untyped workflow stub that can be used to start an external workflow. /// </summary> /// <param name="client">The associated client.</param> /// <param name="workflowTypeName">The workflow type name.</param> /// <param name="execution">The workflow execution.</param> /// <param name="options">The workflow options.</param> internal WorkflowStub(TemporalClient client, string workflowTypeName, WorkflowExecution execution, StartWorkflowOptions options) { Covenant.Requires <ArgumentNullException>(client != null, nameof(client)); Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(workflowTypeName), nameof(workflowTypeName)); Covenant.Requires <ArgumentNullException>(execution != null, nameof(execution)); Covenant.Requires <ArgumentNullException>(options != null, nameof(options)); this.client = client; this.WorkflowTypeName = workflowTypeName; this.Execution = execution; this.Options = options; this.withinWorkflow = false; }
//--------------------------------------------------------------------- // Static members /// <summary> /// Normalizes the options passed by creating or cloning a new instance as /// required and filling unset properties using default client settings. /// </summary> /// <param name="client">The associated Temporal client.</param> /// <param name="options">The input options or <c>null</c>.</param> /// <param name="workflowInterface">Optionally specifies the workflow interface definition.</param> /// /// <param name="method">Optionally specifies the target workflow method.</param> /// <returns>The normalized options.</returns> /// <exception cref="ArgumentNullException">Thrown if a valid task queue is not specified.</exception> internal static StartWorkflowOptions Normalize(TemporalClient client, StartWorkflowOptions options, Type workflowInterface = null, MethodInfo method = null) { Covenant.Requires <ArgumentNullException>(client != null, nameof(client)); WorkflowInterfaceAttribute interfaceAttribute = null; WorkflowMethodAttribute methodAttribute = null; if (options == null) { options = new StartWorkflowOptions(); } else { options = options.Clone(); } if (workflowInterface != null) { TemporalHelper.ValidateWorkflowInterface(workflowInterface); interfaceAttribute = workflowInterface.GetCustomAttribute <WorkflowInterfaceAttribute>(); } if (method != null) { methodAttribute = method.GetCustomAttribute <WorkflowMethodAttribute>(); } if (string.IsNullOrEmpty(options.Namespace)) { if (!string.IsNullOrEmpty(methodAttribute?.Namespace)) { options.Namespace = methodAttribute.Namespace; } if (string.IsNullOrEmpty(options.Namespace) && !string.IsNullOrEmpty(interfaceAttribute?.Namespace)) { options.Namespace = interfaceAttribute.Namespace; } if (string.IsNullOrEmpty(options.Namespace)) { options.Namespace = client.Settings.Namespace; } if (string.IsNullOrEmpty(options.Namespace)) { throw new ArgumentNullException(nameof(options), "You must specify a valid namnespace explicitly in [TemporalSettings], [ActivityOptions] or via an [ActivityInterface] or [ActivityMethod] attribute on the target activity interface or method."); } } if (string.IsNullOrEmpty(options.TaskQueue)) { if (!string.IsNullOrEmpty(methodAttribute?.TaskQueue)) { options.TaskQueue = methodAttribute.TaskQueue; } if (string.IsNullOrEmpty(options.TaskQueue) && !string.IsNullOrEmpty(interfaceAttribute?.TaskQueue)) { options.TaskQueue = interfaceAttribute.TaskQueue; } if (string.IsNullOrEmpty(options.TaskQueue)) { options.TaskQueue = client.Settings.TaskQueue; } if (string.IsNullOrEmpty(options.TaskQueue)) { throw new ArgumentNullException(nameof(options), "You must specify a valid task queue explicitly via [StartWorkflowOptions] or using an [WorkflowInterface] or [WorkflowMethod] attribute on the target workflow interface or method."); } } if (options.WorkflowExecutionTimeout <= TimeSpan.Zero) { if (methodAttribute != null && methodAttribute.WorkflowExecutionTimeoutSeconds > 0) { options.WorkflowExecutionTimeout = TimeSpan.FromSeconds(methodAttribute.WorkflowExecutionTimeoutSeconds); } if (options.WorkflowExecutionTimeout <= TimeSpan.Zero) { options.WorkflowExecutionTimeout = client.Settings.WorkflowExecutionTimeout; } } if (options.WorkflowRunTimeout <= TimeSpan.Zero) { if (methodAttribute != null && methodAttribute.WorkflowRunTimeoutSeconds > 0) { options.WorkflowRunTimeout = TimeSpan.FromSeconds(methodAttribute.WorkflowRunTimeoutSeconds); } if (options.WorkflowRunTimeout <= TimeSpan.Zero) { options.WorkflowRunTimeout = client.Settings.WorkflowRunTimeout; } } if (options.WorkflowTaskTimeout <= TimeSpan.Zero) { if (methodAttribute != null && methodAttribute.WorkflowTaskTimeoutSeconds > 0) { options.WorkflowTaskTimeout = TimeSpan.FromSeconds(methodAttribute.WorkflowTaskTimeoutSeconds); } if (options.WorkflowTaskTimeout <= TimeSpan.Zero) { options.WorkflowTaskTimeout = client.Settings.WorkflowTaskTimeout; } } if (options.WorkflowIdReusePolicy == Temporal.WorkflowIdReusePolicy.UseDefault) { if (methodAttribute != null && methodAttribute.WorkflowIdReusePolicy != WorkflowIdReusePolicy.UseDefault) { options.WorkflowIdReusePolicy = methodAttribute.WorkflowIdReusePolicy; } if (options.WorkflowIdReusePolicy == Temporal.WorkflowIdReusePolicy.UseDefault) { options.WorkflowIdReusePolicy = client.Settings.WorkflowIdReusePolicy; } } if (string.IsNullOrEmpty(options.CronSchedule) && !string.IsNullOrEmpty(methodAttribute?.CronSchedule)) { options.CronSchedule = methodAttribute.CronSchedule; } return(options); }