예제 #1
0
        internal HttpManagementPayload CreateHttpManagementPayload(
            string instanceId,
            string taskHub,
            string connectionName)
        {
            HttpManagementPayload httpManagementPayload = this.GetClientResponseLinks(null, instanceId, taskHub, connectionName);

            return(httpManagementPayload);
        }
예제 #2
0
        internal HttpResponseMessage CreateCheckStatusResponse(
            HttpRequestMessage request,
            string instanceId,
            OrchestrationClientAttribute attribute)
        {
            HttpManagementPayload httpManagementPayload = this.GetClientResponseLinks(request, instanceId, attribute?.TaskHub, attribute?.ConnectionName);

            return(this.CreateCheckStatusResponseMessage(request, httpManagementPayload.Id, httpManagementPayload.StatusQueryGetUri, httpManagementPayload.SendEventPostUri, httpManagementPayload.TerminatePostUri, httpManagementPayload.RewindPostUri));
        }
        internal async Task <HttpResponseMessage> WaitForCompletionOrCreateCheckStatusResponseAsync(
            HttpRequestMessage request,
            string instanceId,
            OrchestrationClientAttribute attribute,
            TimeSpan timeout,
            TimeSpan retryInterval)
        {
            if (retryInterval > timeout)
            {
                throw new ArgumentException($"Total timeout {timeout.TotalSeconds} should be bigger than retry timeout {retryInterval.TotalSeconds}");
            }

            HttpManagementPayload httpManagementPayload = this.GetClientResponseLinks(request, instanceId, attribute?.TaskHub, attribute?.ConnectionName);

            DurableOrchestrationClientBase client = this.GetClient(request);
            Stopwatch stopwatch = Stopwatch.StartNew();

            while (true)
            {
                DurableOrchestrationStatus status = await client.GetStatusAsync(instanceId);

                if (status != null)
                {
                    if (status.RuntimeStatus == OrchestrationRuntimeStatus.Completed)
                    {
                        return(request.CreateResponse(HttpStatusCode.OK, status.Output));
                    }

                    if (status.RuntimeStatus == OrchestrationRuntimeStatus.Canceled ||
                        status.RuntimeStatus == OrchestrationRuntimeStatus.Failed ||
                        status.RuntimeStatus == OrchestrationRuntimeStatus.Terminated)
                    {
                        return(await this.HandleGetStatusRequestAsync(request, instanceId));
                    }
                }

                TimeSpan elapsed = stopwatch.Elapsed;
                if (elapsed < timeout)
                {
                    TimeSpan remainingTime = timeout.Subtract(elapsed);
                    await Task.Delay(remainingTime > retryInterval?retryInterval : remainingTime);
                }
                else
                {
                    return(this.CreateCheckStatusResponseMessage(
                               request,
                               instanceId,
                               httpManagementPayload.StatusQueryGetUri,
                               httpManagementPayload.SendEventPostUri,
                               httpManagementPayload.TerminatePostUri,
                               httpManagementPayload.RewindPostUri,
                               httpManagementPayload.PurgeHistoryDeleteUri));
                }
            }
        }
        internal HttpResponseMessage CreateCheckStatusResponse(
            HttpRequestMessage request,
            string instanceId,
            DurableClientAttribute attribute,
            bool returnInternalServerErrorOnFailure = false)
        {
            HttpManagementPayload httpManagementPayload = this.GetClientResponseLinks(request, instanceId, attribute?.TaskHub, attribute?.ConnectionName, returnInternalServerErrorOnFailure);

            return(this.CreateCheckStatusResponseMessage(
                       request,
                       httpManagementPayload.Id,
                       httpManagementPayload.StatusQueryGetUri,
                       httpManagementPayload.SendEventPostUri,
                       httpManagementPayload.TerminatePostUri,
                       httpManagementPayload.PurgeHistoryDeleteUri));
        }
        private HttpManagementPayload GetClientResponseLinks(
            HttpRequestMessage request,
            string instanceId,
            string taskHubName,
            string connectionName,
            bool returnInternalServerErrorOnFailure = false)
        {
            this.ThrowIfWebhooksNotConfigured();

            Uri notificationUri = this.config.Options.NotificationUrl;
            Uri baseUri         = request?.RequestUri ?? notificationUri;

            // e.g. http://{host}/admin/extensions/DurableTaskExtension?code={systemKey}
            string hostUrl            = baseUri.GetLeftPart(UriPartial.Authority);
            string baseUrl            = hostUrl + notificationUri.AbsolutePath.TrimEnd('/');
            string allInstancesPrefix = baseUrl + "/" + InstancesControllerSegment;
            string instancePrefix     = allInstancesPrefix + WebUtility.UrlEncode(instanceId);

            string taskHub    = WebUtility.UrlEncode(taskHubName ?? this.config.Options.HubName);
            string connection = WebUtility.UrlEncode(connectionName ?? this.config.GetDefaultConnectionName());

            string querySuffix = $"{TaskHubParameter}={taskHub}&{ConnectionParameter}={connection}";

            if (!string.IsNullOrEmpty(notificationUri.Query))
            {
                // This is expected to include the auto-generated system key for this extension.
                querySuffix += "&" + notificationUri.Query.TrimStart('?');
            }

            var httpManagementPayload = new HttpManagementPayload
            {
                Id = instanceId,
                StatusQueryGetUri     = instancePrefix + "?" + querySuffix,
                SendEventPostUri      = instancePrefix + "/" + RaiseEventOperation + "/{eventName}?" + querySuffix,
                TerminatePostUri      = instancePrefix + "/" + TerminateOperation + "?reason={text}&" + querySuffix,
                RewindPostUri         = instancePrefix + "/" + RewindOperation + "?reason={text}&" + querySuffix,
                PurgeHistoryDeleteUri = instancePrefix + "?" + querySuffix,
            };

            if (returnInternalServerErrorOnFailure)
            {
                httpManagementPayload.StatusQueryGetUri += "&returnInternalServerErrorOnFailure=true";
            }

            return(httpManagementPayload);
        }
예제 #6
0
        private HttpManagementPayload GetClientResponseLinks(
            HttpRequestMessage request,
            string instanceId,
            string taskHubName,
            string connectionName)
        {
            if (this.config.Options.NotificationUrl == null)
            {
                throw new InvalidOperationException("Webhooks are not configured");
            }

            Uri notificationUri = this.config.Options.NotificationUrl;
            Uri baseUri         = request?.RequestUri ?? notificationUri;

            // e.g. http://{host}/admin/extensions/DurableTaskExtension?code={systemKey}
            string hostUrl        = baseUri.GetLeftPart(UriPartial.Authority);
            string baseUrl        = hostUrl + notificationUri.AbsolutePath.TrimEnd('/');
            string instancePrefix = baseUrl + InstancesControllerSegment + WebUtility.UrlEncode(instanceId);

            string taskHub    = WebUtility.UrlEncode(taskHubName ?? this.config.Options.HubName);
            string connection = WebUtility.UrlEncode(connectionName ?? this.config.Options.AzureStorageConnectionStringName ?? ConnectionStringNames.Storage);

            string querySuffix = $"{TaskHubParameter}={taskHub}&{ConnectionParameter}={connection}";

            if (!string.IsNullOrEmpty(notificationUri.Query))
            {
                // This is expected to include the auto-generated system key for this extension.
                querySuffix += "&" + notificationUri.Query.TrimStart('?');
            }

            HttpManagementPayload httpManagementPayload = new HttpManagementPayload
            {
                Id = instanceId,
                StatusQueryGetUri = instancePrefix + "?" + querySuffix,
                SendEventPostUri  = instancePrefix + "/" + RaiseEventOperation + "/{eventName}?" + querySuffix,
                TerminatePostUri  = instancePrefix + "/" + TerminateOperation + "?reason={text}&" + querySuffix,
                RewindPostUri     = instancePrefix + "/" + RewindOperation + "?reason={text}&" + querySuffix,
            };

            return(httpManagementPayload);
        }