/// <summary> /// Handles workflow local activity invocations. /// </summary> /// <param name="request">The request message.</param> /// <returns>The reply message.</returns> internal async Task <ActivityInvokeLocalReply> OnInvokeLocalActivity(ActivityInvokeLocalRequest request) { await SyncContext.Clear; Covenant.Requires <ArgumentNullException>(request != null, nameof(request)); try { WorkflowBase.CallContext.Value = WorkflowCallContext.Activity; var workflow = GetWorkflow(request.ContextId); if (workflow != null) { var activityAction = workflow.GetActivityAction(request.ActivityTypeId); if (activityAction == null) { return(new ActivityInvokeLocalReply() { Error = new EntityNotExistsException($"Activity type does not exist for [activityTypeId={request.ActivityTypeId}].").ToTemporalError() }); } var workerArgs = new WorkerArgs() { Worker = this, ContextId = request.ActivityContextId }; var activity = CreateLocalActivity(activityAction, request.ActivityContextId); var result = await activity.OnInvokeAsync(request.Args); return(new ActivityInvokeLocalReply() { Result = result }); } else { return(new ActivityInvokeLocalReply() { Error = new EntityNotExistsException($"Workflow with [contextID={request.ContextId}] does not exist.").ToTemporalError() }); } } catch (Exception e) { log.LogError(e); return(new ActivityInvokeLocalReply() { Error = new TemporalError(e) }); } finally { WorkflowBase.CallContext.Value = WorkflowCallContext.None; } }
/// <summary> /// Handles workflow local activity invocations. /// </summary> /// <param name="client">The client the request was received from.</param> /// <param name="request">The request message.</param> /// <returns>The reply message.</returns> internal static async Task <ActivityInvokeLocalReply> OnInvokeLocalActivity(CadenceClient client, ActivityInvokeLocalRequest request) { Covenant.Requires <ArgumentNullException>(request != null); try { var workflow = GetWorkflow(client, request.ContextId); if (workflow != null) { LocalActivityAction activityAction; lock (syncLock) { if (!workflow.Workflow.IdToLocalActivityAction.TryGetValue(request.ActivityTypeId, out activityAction)) { return(new ActivityInvokeLocalReply() { Error = new CadenceEntityNotExistsException($"Activity type does not exist for [activityTypeId={request.ActivityTypeId}].").ToCadenceError() }); } } var workerArgs = new WorkerArgs() { Client = client, ContextId = request.ActivityContextId }; var activity = ActivityBase.Create(client, activityAction, null); var result = await activity.OnRunAsync(client, request.Args); return(new ActivityInvokeLocalReply() { Result = result }); } else { return(new ActivityInvokeLocalReply() { Error = new CadenceEntityNotExistsException($"Workflow with [contextID={request.ContextId}] does not exist.").ToCadenceError() }); } } catch (Exception e) { return(new ActivityInvokeLocalReply() { Error = new CadenceError(e) }); } }