public async Task Renew(TaskOrchestrationWorkItem workItem) { var request = new TaskOrchestrationRequest { RenewRequest = new RenewTaskOrchestrationWorkItemLockRequest() }; await _stream.RequestStream.WriteAsync(request); var cts = new CancellationTokenSource(_renewResponseTimeout); if (!await _stream.ResponseStream.MoveNext(cts.Token)) { throw new Exception("Session aborted"); } if (_stream.ResponseStream.Current.MessageCase != TaskOrchestrationResponse.MessageOneofCase.RenewResponse) { throw new Exception("Unexpected response"); } var renewResponse = _stream.ResponseStream.Current.RenewResponse; workItem.LockedUntilUtc = renewResponse.LockedUntilUtc.ToDateTime(); }
public async Task Release(TaskOrchestrationWorkItem workItem) { var request = new TaskOrchestrationRequest { ReleaseRequest = new ReleaseTaskOrchestrationWorkItemRequest() }; await _stream.RequestStream.WriteAsync(request); var cts = new CancellationTokenSource(_releaseResponseTimeout); if (!await _stream.ResponseStream.MoveNext(cts.Token)) { throw new Exception("Session aborted"); } if (_stream.ResponseStream.Current.MessageCase != TaskOrchestrationResponse.MessageOneofCase.ReleaseResponse) { throw new Exception("Unexpected response"); } await _stream.RequestStream.CompleteAsync(); // Last read to close stream await _stream.ResponseStream.MoveNext(cts.Token); _stream.Dispose(); }
public async Task <IList <TaskMessage> > FetchNewOrchestrationMessagesAsync( TaskOrchestrationWorkItem workItem) { var request = new TaskOrchestrationRequest { FetchRequest = new FetchNewOrchestrationMessagesRequest() }; await _stream.RequestStream.WriteAsync(request); var cts = new CancellationTokenSource(_fetchResponseTimeout); if (!await _stream.ResponseStream.MoveNext(cts.Token)) { throw new Exception("Session aborted"); } if (_stream.ResponseStream.Current.MessageCase != TaskOrchestrationResponse.MessageOneofCase.FetchResponse) { throw new Exception("Unexpected response"); } var fetchResponse = _stream.ResponseStream.Current.FetchResponse; if (fetchResponse.NewMessages == null) { return(null); } return(fetchResponse.NewMessages.Messages .Select(x => _options.DataConverter.Deserialize <TaskMessage>(x)) .ToArray()); }
public async Task Complete( TaskOrchestrationWorkItem workItem, OrchestrationRuntimeState newOrchestrationRuntimeState, IList <TaskMessage> outboundMessages, IList <TaskMessage> orchestratorMessages, IList <TaskMessage> timerMessages, TaskMessage continuedAsNewMessage, OrchestrationState orchestrationState) { var request = new TaskOrchestrationRequest { CompleteRequest = new CompleteTaskOrchestrationWorkItemRequest { NewEvents = { workItem.OrchestrationRuntimeState.NewEvents.Select(_options.DataConverter.Serialize) }, NewStatus = workItem.OrchestrationRuntimeState.Status, NewOrchestrationEvents = { newOrchestrationRuntimeState == workItem.OrchestrationRuntimeState ? Enumerable.Empty <string>() : newOrchestrationRuntimeState.NewEvents.Select(_options.DataConverter.Serialize) }, NewOrchestrationStatus = newOrchestrationRuntimeState == workItem.OrchestrationRuntimeState ? null : newOrchestrationRuntimeState.Status, OutboundMessages = { outboundMessages.Select(_options.DataConverter.Serialize) }, OrchestratorMessages = { orchestratorMessages.Select(_options.DataConverter.Serialize) }, TimerMessages = { timerMessages.Select(_options.DataConverter.Serialize) }, ContinuedAsNewMessage = continuedAsNewMessage == null ? string.Empty : _options.DataConverter.Serialize(continuedAsNewMessage), OrchestrationState = _options.DataConverter.Serialize(orchestrationState) } }; await _stream.RequestStream.WriteAsync(request); var cts = new CancellationTokenSource(_completeResponseTimeout); if (!await _stream.ResponseStream.MoveNext(cts.Token)) { throw new Exception("Session aborted"); } if (_stream.ResponseStream.Current.MessageCase != TaskOrchestrationResponse.MessageOneofCase.CompleteResponse) { throw new Exception("Unexpected response"); } }
public async Task Abandon(TaskOrchestrationWorkItem workItem) { var request = new TaskOrchestrationRequest { AbandonRequest = new AbandonTaskOrchestrationWorkItemLockRequest() }; await _stream.RequestStream.WriteAsync(request); var cts = new CancellationTokenSource(_abandonResponseTimeout); if (!await _stream.ResponseStream.MoveNext(cts.Token)) { throw new Exception("Session aborted"); } if (_stream.ResponseStream.Current.MessageCase != TaskOrchestrationResponse.MessageOneofCase.AbandonResponse) { throw new Exception("Unexpected response"); } }
private async Task <TaskOrchestrationWorkItem> LockNextTaskOrchestrationWorkItemAsync( TimeSpan receiveTimeout, INameVersionInfo[] orchestrations, bool allOrchesrations, CancellationToken cancellationToken) { var stream = _client.LockNextTaskOrchestrationWorkItem(cancellationToken: cancellationToken); try { var request = new TaskOrchestrationRequest { LockRequest = new LockNextTaskOrchestrationWorkItemRequest { ReceiveTimeout = Duration.FromTimeSpan(receiveTimeout), Orchestrations = { orchestrations .Select(nv => new NameVersion { Name = nv.Name, Version = nv.Version }) }, AllOrchestrations = allOrchesrations } }; await stream.RequestStream.WriteAsync(request); if (!await stream.ResponseStream.MoveNext(cancellationToken)) { throw new Exception("Session aborted"); } if (stream.ResponseStream.Current.MessageCase != TaskOrchestrationResponse.MessageOneofCase.LockResponse) { throw new Exception("Didn't receive lock response"); } var lockResponse = stream.ResponseStream.Current.LockResponse; if (lockResponse.WorkItem == null) { return(null); } return(new TaskOrchestrationWorkItem { InstanceId = lockResponse.WorkItem.InstanceId, OrchestrationRuntimeState = new OrchestrationRuntimeState( lockResponse.WorkItem.Events .Select(e => _options.DataConverter.Deserialize <HistoryEvent>(e)) .ToArray()), LockedUntilUtc = lockResponse.WorkItem.LockedUntilUtc.ToDateTime(), NewMessages = lockResponse.WorkItem.NewMessages.Select(m => _options.DataConverter.Deserialize <TaskMessage>(m)).ToArray(), Session = new GrpcClientOrchestrationSession(_options, stream, _logger) }); } catch { stream.Dispose(); throw; } }