/// <summary> /// Creates a stub suitable for starting an external workflow and then waiting /// for the result as separate operations. /// </summary> /// <typeparam name="TWorkflowInterface">The target workflow interface.</typeparam> /// <param name="methodName"> /// Optionally identifies the target workflow method. This is the name specified in /// <c>[WorkflowMethod]</c> attribute for the workflow method or <c>null</c>/empty for /// the default workflow method. /// </param> /// <param name="options">Optionally specifies custom <see cref="WorkflowOptions"/>.</param> /// <returns>A <see cref="ChildWorkflowStub{TWorkflowInterface}"/> instance.</returns> public WorkflowFutureStub <TWorkflowInterface> NewWorkflowFutureStub <TWorkflowInterface>(string methodName = null, WorkflowOptions options = null) where TWorkflowInterface : class { CadenceHelper.ValidateWorkflowInterface(typeof(TWorkflowInterface)); EnsureNotDisposed(); options = WorkflowOptions.Normalize(this, options, typeof(TWorkflowInterface)); return(new WorkflowFutureStub <TWorkflowInterface>(this, methodName, options)); }
/// <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(CadenceClient client, string methodName = null, WorkflowOptions options = null) { Covenant.Requires <ArgumentNullException>(client != null, nameof(client)); var workflowInterface = typeof(WorkflowInterface); CadenceHelper.ValidateWorkflowInterface(workflowInterface); this.client = client; this.workflowTypeName = CadenceHelper.GetWorkflowTarget(workflowInterface, methodName).WorkflowTypeName; this.options = WorkflowOptions.Normalize(client, options); }
//--------------------------------------------------------------------- // Internal workflow related methods used by dynamically generated workflow stubs. /// <summary> /// Starts an external workflow using a specific workflow type name, returning a <see cref="WorkflowExecution"/> /// that can be used to track the workflow and also wait for its result via <see cref="GetWorkflowResultAsync(WorkflowExecution, string)"/>. /// </summary> /// <param name="workflowTypeName"> /// The type name used when registering the workers that will handle this workflow. /// This name will often be the fully qualified name of the workflow type but /// this may have been customized when the workflow worker was registered. /// </param> /// <param name="args">Specifies the workflow arguments encoded into a byte array.</param> /// <param name="options">Specifies the workflow options.</param> /// <returns>A <see cref="WorkflowExecution"/> identifying the new running workflow instance.</returns> /// <exception cref="EntityNotExistsException">Thrown if there is no workflow registered for <paramref name="workflowTypeName"/>.</exception> /// <exception cref="BadRequestException">Thrown if the request is not valid.</exception> /// <exception cref="WorkflowRunningException">Thrown if a workflow with this ID is already running.</exception> /// <remarks> /// This method kicks off a new workflow instance and returns after Cadence has /// queued the operation but the method <b>does not</b> wait for the workflow to /// complete. /// </remarks> internal async Task <WorkflowExecution> StartWorkflowAsync(string workflowTypeName, byte[] args, WorkflowOptions options) { Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(workflowTypeName), nameof(workflowTypeName)); EnsureNotDisposed(); options = WorkflowOptions.Normalize(this, options); var reply = (WorkflowExecuteReply) await CallProxyAsync( new WorkflowExecuteRequest() { Workflow = workflowTypeName, Domain = options.Domain, Args = args, Options = options.ToInternal() }); reply.ThrowOnError(); var execution = reply.Execution; return(new WorkflowExecution(execution.ID, execution.RunID)); }
/// <summary> /// Transmits a signal to an external workflow, starting the workflow if it's not currently running. /// This low-level method accepts a byte array with the already encoded parameters. /// </summary> /// <param name="workflowTypeName">The target workflow type name.</param> /// <param name="signalName">Identifies the signal.</param> /// <param name="signalArgs">Optionally specifies the signal arguments as a byte array.</param> /// <param name="startArgs">Optionally specifies the workflow arguments.</param> /// <param name="options">Optionally specifies the options to be used for starting the workflow when required.</param> /// <returns>The <see cref="WorkflowExecution"/>.</returns> /// <exception cref="EntityNotExistsException">Thrown if the domain does not exist.</exception> /// <exception cref="BadRequestException">Thrown if the request is invalid.</exception> /// <exception cref="InternalServiceException">Thrown for internal Cadence problems.</exception> internal async Task <WorkflowExecution> SignalWorkflowWithStartAsync(string workflowTypeName, string signalName, byte[] signalArgs, byte[] startArgs, WorkflowOptions options) { Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(workflowTypeName), nameof(workflowTypeName)); Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(signalName), nameof(signalName)); EnsureNotDisposed(); options = WorkflowOptions.Normalize(this, options); var reply = (WorkflowSignalWithStartReply) await CallProxyAsync( new WorkflowSignalWithStartRequest() { Workflow = workflowTypeName, WorkflowId = options.WorkflowId, Options = options.ToInternal(), SignalName = signalName, SignalArgs = signalArgs, WorkflowArgs = startArgs, Domain = options.Domain }); reply.ThrowOnError(); return(reply.Execution.ToPublic()); }