예제 #1
0
        public async override Task <string> RunAsync(TaskContext context, string rawInput)
        {
            DurableHttpRequest durableHttpRequest = ReconstructDurableHttpRequest(rawInput);
            HttpRequestMessage requestMessage     = await this.ConvertToHttpRequestMessage(durableHttpRequest);

            HttpResponseMessage response;

            if (durableHttpRequest.Timeout == null)
            {
                response = await this.httpClient.SendAsync(requestMessage);
            }
            else
            {
                try
                {
                    using (CancellationTokenSource cts = new CancellationTokenSource())
                    {
                        cts.CancelAfter(durableHttpRequest.Timeout.Value);
                        response = await this.httpClient.SendAsync(requestMessage, cts.Token);
                    }
                }
                catch (OperationCanceledException ex)
                {
                    TimeoutException e = new TimeoutException(ex.Message + $" Reached user specified timeout: {durableHttpRequest.Timeout.Value}.");

                    string details = Utils.SerializeCause(e, this.config.ErrorDataConverter);
                    throw new TaskFailureException(e.Message, e, details);
                }
            }

            DurableHttpResponse durableHttpResponse = await DurableHttpResponse.CreateDurableHttpResponseWithHttpResponseMessage(response);

            return(JsonConvert.SerializeObject(durableHttpResponse));
        }
        public async override Task <string> RunAsync(TaskContext context, string rawInput)
        {
            HttpRequestMessage requestMessage = await this.ReconstructHttpRequestMessage(rawInput);

            HttpResponseMessage response = await this.httpClient.SendAsync(requestMessage);

            DurableHttpResponse durableHttpResponse = await DurableHttpResponse.CreateDurableHttpResponseWithHttpResponseMessage(response);

            return(JsonConvert.SerializeObject(durableHttpResponse));
        }