Exemple #1
0
        internal virtual async Task <bool> UpdateQueueMetrics()
        {
            CloudQueue workItemQueue = AzureStorageOrchestrationService.GetWorkItemQueue(this.storageAccount, this.taskHub);

            CloudQueue[] controlQueues = await AzureStorageOrchestrationService.GetControlQueuesAsync(
                this.storageAccount,
                this.taskHub,
                defaultPartitionCount : AzureStorageOrchestrationServiceSettings.DefaultPartitionCount);

            Task <QueueMetric>         workItemMetricTask      = GetQueueMetricsAsync(workItemQueue);
            List <Task <QueueMetric> > controlQueueMetricTasks = controlQueues.Select(GetQueueMetricsAsync).ToList();

            var tasks = new List <Task>(controlQueueMetricTasks.Count + 1);

            tasks.Add(workItemMetricTask);
            tasks.AddRange(controlQueueMetricTasks);

            try
            {
                await Task.WhenAll(tasks);
            }
            catch (StorageException e) when(e.RequestInformation?.HttpStatusCode == 404)
            {
                // The queues are not yet provisioned.
                AnalyticsEventSource.Log.MonitorWarning(
                    this.storageAccount.Credentials.AccountName,
                    this.taskHub,
                    $"Task hub has not been provisioned: {e.RequestInformation.ExtendedErrorInformation?.ErrorMessage}");
                return(false);
            }

            QueueMetric workItemQueueMetric = workItemMetricTask.Result;

            this.WorkItemQueueLatencies.Add((int)workItemQueueMetric.Latency.TotalMilliseconds);

            int i;

            for (i = 0; i < controlQueueMetricTasks.Count; i++)
            {
                QueueMetric controlQueueMetric = controlQueueMetricTasks[i].Result;
                if (i >= this.ControlQueueLatencies.Count)
                {
                    this.ControlQueueLatencies.Add(new QueueMetricHistory(QueueLengthSampleSize));
                }

                this.ControlQueueLatencies[i].Add((int)controlQueueMetric.Latency.TotalMilliseconds);
            }

            // Handle the case where the number of control queues has been reduced since we last checked.
            while (i < this.ControlQueueLatencies.Count && this.ControlQueueLatencies.Count > 0)
            {
                this.ControlQueueLatencies.RemoveAt(this.ControlQueueLatencies.Count - 1);
            }

            this.currentPartitionCount      = controlQueues.Length;
            this.currentWorkItemQueueLength = workItemQueueMetric.Length;
            this.currentControlQueueLengths = controlQueueMetricTasks.Select(t => t.Result.Length).ToArray();

            return(true);
        }
        public static async Task <IActionResult> Run(
            // Using /a/p/i route prefix, to let Functions Host distinguish api methods from statics
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "a/p/i/delete-task-hub")] HttpRequest req
            )
        {
            // Checking that the call is authenticated properly
            try
            {
                Globals.ValidateIdentity(req.HttpContext.User, req.Headers);
            }
            catch (UnauthorizedAccessException ex)
            {
                return(new OkObjectResult(ex.Message)
                {
                    StatusCode = 401
                });
            }

            string hubName          = Environment.GetEnvironmentVariable(EnvVariableNames.DFM_HUB_NAME);
            string connectionString = Environment.GetEnvironmentVariable(EnvVariableNames.AzureWebJobsStorage);

            var orcService = new AzureStorageOrchestrationService(new AzureStorageOrchestrationServiceSettings
            {
                StorageConnectionString = connectionString,
                TaskHubName             = hubName,
            });

            await orcService.DeleteAsync();

            return(new OkResult());
        }
Exemple #3
0
        /// <inheritdoc />
        public override Task PurgeInstanceHistoryAsync(DateTime createdTimeFrom, DateTime?createdTimeTo, IEnumerable <OrchestrationStatus> runtimeStatus)
        {
            // TODO this cast is to avoid to change DurableTask.Core. Change it to use TaskHubClient.
            AzureStorageOrchestrationService serviceClient = (AzureStorageOrchestrationService)this.client.ServiceClient;

            return(serviceClient.PurgeInstanceHistoryAsync(createdTimeFrom, createdTimeTo, runtimeStatus));
        }
Exemple #4
0
        public static void Main(string[] args)
        {
            AzureStorageOrchestrationService orchestrationService = new AzureStorageOrchestrationService(new AzureStorageOrchestrationServiceSettings()
            {
                StorageConnectionString = ServiceSettings.StorageConnectionString,
                TaskHubName             = ServiceSettings.TaskHubName
            });

            TaskHubClient client = new TaskHubClient(orchestrationService);

            Console.WriteLine("Enter -1 to exit anything else will be fed to the orchestration");
            do
            {
                var s = Console.ReadLine();

                if (s == "-1")
                {
                    break;
                }

                var instance = client.CreateOrchestrationInstanceAsync(typeof(LetterCountOrchestration), s).Result;
                Console.WriteLine("Workflow Instance Started: " + instance);

                var result = client.WaitForOrchestrationAsync(instance, TimeSpan.MaxValue).Result;

                Console.WriteLine($"Task done: {result?.OrchestrationStatus}");
            } while (1 == 1);
        }
Exemple #5
0
        public LegacyPartitionManager(
            AzureStorageOrchestrationService service,
            AzureStorageOrchestrationServiceSettings settings,
            CloudStorageAccount account,
            AzureStorageOrchestrationServiceStats stats)
        {
            this.service      = service;
            this.settings     = settings;
            this.stats        = stats;
            this.leaseManager = new BlobLeaseManager(
                settings,
                settings.TaskHubName.ToLowerInvariant() + "-leases",
                string.Empty,
                "default",
                account.CreateCloudBlobClient(),
                skipBlobContainerCreation: false,
                stats);

            this.leaseCollectionManager = new LeaseCollectionBalancer <BlobLease>(
                "default",
                settings,
                account.Credentials.AccountName,
                leaseManager,
                new LeaseCollectionBalancerOptions
            {
                AcquireInterval   = settings.LeaseAcquireInterval,
                RenewInterval     = settings.LeaseRenewInterval,
                LeaseInterval     = settings.LeaseInterval,
                ShouldStealLeases = true,
            });
        }
 public TestOrchestrationHost(AzureStorageOrchestrationService service)
 {
     this.worker = new TaskHubWorker(service);
     this.client = new TaskHubClient(service);
     this.addedOrchestrationTypes = new HashSet <Type>();
     this.addedActivityTypes      = new HashSet <Type>();
 }
Exemple #7
0
        /// <inheritdoc />
        public override Task PurgeInstanceHistoryAsync(string instanceId)
        {
            // TODO this cast is to avoid to change DurableTask.Core. Change it to use TaskHubClient.
            AzureStorageOrchestrationService serviceClient = (AzureStorageOrchestrationService)this.client.ServiceClient;

            return(serviceClient.PurgeInstanceHistoryAsync(instanceId));
        }
        private void SetStorageServiceAndTaskHubClient(out AzureStorageOrchestrationService orchestrationService, out TaskHubClient taskHubClient, string connectionStringKey = null, string taskHubName = null)
        {
            _connectionStringKey = connectionStringKey ?? _connectionStringKey;
            _taskHubName         = taskHubName ?? _taskHubName;

            var connectionString = Environment.GetEnvironmentVariable(_connectionStringKey); // Prioritize environment variables

            connectionString = connectionString ?? _secretsManager.GetSecrets().FirstOrDefault(s => s.Key.Equals(_connectionStringKey, StringComparison.OrdinalIgnoreCase)).Value;

            if (!string.IsNullOrEmpty(connectionString))
            {
                var settings = new AzureStorageOrchestrationServiceSettings
                {
                    TaskHubName             = _taskHubName,
                    StorageConnectionString = connectionString,
                };

                orchestrationService = new AzureStorageOrchestrationService(settings);
                taskHubClient        = new TaskHubClient(orchestrationService);
            }
            else
            {
                throw new CliException("No storage connection string found.");
            }
        }
Exemple #9
0
        /// <summary>
        /// Gets a <see cref="DurableOrchestrationClient"/> using configuration from a <see cref="OrchestrationClientAttribute"/> instance.
        /// </summary>
        /// <param name="attribute">The attribute containing the client configuration parameters.</param>
        /// <returns>Returns a <see cref="DurableOrchestrationClient"/> instance. The returned instance may be a cached instance.</returns>
        protected internal virtual DurableOrchestrationClient GetClient(OrchestrationClientAttribute attribute)
        {
            DurableOrchestrationClient client = this.cachedClients.GetOrAdd(
                attribute,
                attr =>
            {
                AzureStorageOrchestrationServiceSettings settings = this.GetOrchestrationServiceSettings(attr);

                AzureStorageOrchestrationService innerClient;
                if (this.orchestrationServiceSettings != null &&
                    this.orchestrationService != null &&
                    string.Equals(this.orchestrationServiceSettings.TaskHubName, settings.TaskHubName, StringComparison.OrdinalIgnoreCase) &&
                    string.Equals(this.orchestrationServiceSettings.StorageConnectionString, settings.StorageConnectionString, StringComparison.OrdinalIgnoreCase))
                {
                    // It's important that clients use the same AzureStorageOrchestrationService instance
                    // as the host when possible to ensure we any send operations can be picked up
                    // immediately instead of waiting for the next queue polling interval.
                    innerClient = this.orchestrationService;
                }
                else
                {
                    innerClient = new AzureStorageOrchestrationService(settings);
                }

                return(new DurableOrchestrationClient(innerClient, this, attr));
            });

            return(client);
        }
        public async Task <IList <OrchestrationState> > GetStateAsync(string instanceId)
        {
            Trace.TraceInformation($"Getting orchestration state with instance id - {this.instanceId}");
            // The GetStateAsync only exists in the service object
            AzureStorageOrchestrationService service = (AzureStorageOrchestrationService)this.client.ServiceClient;

            return(await service.GetOrchestrationStateAsync(instanceId, true));
        }
        public Task RewindAsync(string reason)
        {
            Trace.TraceInformation($"Rewinding instance {this.instanceId} with reason = {reason}.");

            // The Rewind API currently only exists in the service object
            AzureStorageOrchestrationService service = (AzureStorageOrchestrationService)this.client.serviceClient;

            return(service.RewindTaskOrchestrationAsync(this.instanceId, reason));
        }
        public async Task <IList <OrchestrationState> > GetAllOrchestrationInstancesAsync()
        {
            // This API currently only exists in the service object and is not yet exposed on the TaskHubClient
            AzureStorageOrchestrationService service   = (AzureStorageOrchestrationService)this.client.ServiceClient;
            IList <OrchestrationState>       instances = await service.GetOrchestrationStateAsync();

            Trace.TraceInformation($"Found {instances.Count} in the task hub instance store.");
            return(instances);
        }
        public Task PurgeInstanceHistoryByTimePeriod(DateTime createdTimeFrom, DateTime?createdTimeTo, IEnumerable <OrchestrationStatus> runtimeStatus)
        {
            Trace.TraceInformation($"Purging history from {createdTimeFrom} to {createdTimeTo}");

            // The Purge Instance History API only exists in the service object
            AzureStorageOrchestrationService service = (AzureStorageOrchestrationService)this.client.ServiceClient;

            return(service.PurgeInstanceHistoryAsync(createdTimeFrom, createdTimeTo, runtimeStatus));
        }
        public Task PurgeInstanceHistory()
        {
            Trace.TraceInformation($"Purging history for instance with id - {this.instanceId}");

            // The Purge Instance History API only exists in the service object
            AzureStorageOrchestrationService service = (AzureStorageOrchestrationService)this.client.ServiceClient;

            return(service.PurgeInstanceHistoryAsync(this.instanceId));
        }
        async Task DequeueLoop(string partitionId, ControlQueue controlQueue, CancellationToken cancellationToken)
        {
            this.settings.Logger.PartitionManagerInfo(
                this.storageAccountName,
                this.settings.TaskHubName,
                this.settings.WorkerId,
                partitionId,
                $"Started listening for messages on queue {controlQueue.Name}.");

            while (!controlQueue.IsReleased)
            {
                try
                {
                    // Every dequeue operation has a common trace ID so that batches of dequeued messages can be correlated together.
                    // Both the dequeue traces and the processing traces will share the same "related" trace activity ID.
                    Guid traceActivityId = AzureStorageOrchestrationService.StartNewLogicalTraceScope(useExisting: false);

                    // This will block until either new messages arrive or the queue is released.
                    IReadOnlyList <MessageData> messages = await controlQueue.GetMessagesAsync(cancellationToken);

                    if (messages.Count > 0)
                    {
                        // De-dupe any execution started messages
                        IEnumerable <MessageData> filteredMessages = await this.DedupeExecutionStartedMessagesAsync(
                            controlQueue,
                            messages,
                            traceActivityId,
                            cancellationToken);

                        this.AddMessageToPendingOrchestration(controlQueue, filteredMessages, traceActivityId, cancellationToken);
                    }
                }
                catch (OperationCanceledException) when(cancellationToken.IsCancellationRequested)
                {
                    // shutting down
                    break;
                }
                catch (Exception e)
                {
                    this.settings.Logger.PartitionManagerWarning(
                        this.storageAccountName,
                        this.settings.TaskHubName,
                        this.settings.WorkerId,
                        partitionId,
                        $"Exception in the dequeue loop for control queue {controlQueue.Name}. Exception: {e}");

                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
            }

            this.settings.Logger.PartitionManagerInfo(
                this.storageAccountName,
                this.settings.TaskHubName,
                this.settings.WorkerId,
                partitionId,
                $"Stopped listening for messages on queue {controlQueue.Name}.");
        }
        /// <inheritdoc />
        public override async Task <PurgeHistoryResult> PurgeInstanceHistoryAsync(string instanceId)
        {
            // TODO this cast is to avoid to change DurableTask.Core. Change it to use TaskHubClient.
            AzureStorageOrchestrationService serviceClient = (AzureStorageOrchestrationService)this.client.ServiceClient;

            DurableTask.AzureStorage.PurgeHistoryResult purgeHistoryResult =
                await serviceClient.PurgeInstanceHistoryAsync(instanceId);

            return(new PurgeHistoryResult(purgeHistoryResult.InstancesDeleted));
        }
        public DurabilityProvider GetDurabilityProvider()
        {
            if (this.defaultStorageProvider == null)
            {
                var defaultService = new AzureStorageOrchestrationService(this.defaultSettings);
                this.defaultStorageProvider = new AzureStorageDurabilityProvider(defaultService, this.defaultConnectionName);
            }

            return(this.defaultStorageProvider);
        }
        /// <inheritdoc />
        public override async Task <PurgeHistoryResult> PurgeInstanceHistoryAsync(DateTime createdTimeFrom, DateTime?createdTimeTo, IEnumerable <OrchestrationStatus> runtimeStatus)
        {
            // TODO this cast is to avoid to change DurableTask.Core. Change it to use TaskHubClient.
            AzureStorageOrchestrationService serviceClient = (AzureStorageOrchestrationService)this.client.ServiceClient;

            DurableTask.AzureStorage.PurgeHistoryResult purgeHistoryResult =
                await serviceClient.PurgeInstanceHistoryAsync(createdTimeFrom, createdTimeTo, runtimeStatus);

            return(new PurgeHistoryResult(purgeHistoryResult.InstancesDeleted));
        }
        public async Task <List <HistoryStateEvent> > GetOrchestrationHistoryAsync(string instanceId)
        {
            Trace.TraceInformation($"Getting history for instance with id - {this.instanceId}");

            // GetOrchestrationHistoryAsync is exposed in the TaskHubClinet but requires execution id.
            // However, we need to get all the history records for an instance id not for specific execution.
            AzureStorageOrchestrationService service = (AzureStorageOrchestrationService)this.client.ServiceClient;
            string historyString = await service.GetOrchestrationHistoryAsync(instanceId, null);

            return(JsonConvert.DeserializeObject <List <HistoryStateEvent> >(historyString));
        }
Exemple #20
0
        public TestOrchestrationHost(AzureStorageOrchestrationServiceSettings settings)
        {
            this.service = new AzureStorageOrchestrationService(settings);
            this.service.CreateAsync().GetAwaiter().GetResult();

            this.settings = settings;
            this.worker   = new TaskHubWorker(service, loggerFactory: settings.LoggerFactory);
            this.client   = new TaskHubClient(service, loggerFactory: settings.LoggerFactory);
            this.addedOrchestrationTypes = new HashSet <Type>();
            this.addedActivityTypes      = new HashSet <Type>();
        }
Exemple #21
0
        public async Task MonitorIdleTaskHubDisconnected()
        {
            var settings = new AzureStorageOrchestrationServiceSettings
            {
                StorageConnectionString = TestHelpers.GetTestStorageAccountConnectionString(),
                TaskHubName             = nameof(MonitorIdleTaskHubDisconnected),
                PartitionCount          = 4,
            };

            var service = new AzureStorageOrchestrationService(settings);
            var monitor = new DisconnectedPerformanceMonitor(settings.StorageConnectionString, settings.TaskHubName);

            await service.DeleteAsync();

            // A null heartbeat is expected when the task hub does not exist.
            PerformanceHeartbeat heartbeat = await monitor.PulseAsync(currentWorkerCount : 0);

            Assert.IsNull(heartbeat);

            await service.CreateAsync();

            ScaleRecommendation recommendation;

            for (int i = 0; i < 10; i++)
            {
                heartbeat = await monitor.PulseAsync(currentWorkerCount : 0);

                Assert.IsNotNull(heartbeat);
                Assert.AreEqual(settings.PartitionCount, heartbeat.PartitionCount);
                Assert.AreEqual(settings.PartitionCount, heartbeat.ControlQueueLengths.Count);
                Assert.AreEqual(settings.PartitionCount, heartbeat.ControlQueueLatencies.Count);
                Assert.AreEqual(0, heartbeat.ControlQueueLengths.Count(l => l != 0));
                Assert.AreEqual(0, heartbeat.ControlQueueLatencies.Count(l => l != TimeSpan.Zero));
                Assert.AreEqual(0, heartbeat.WorkItemQueueLength);
                Assert.AreEqual(0.0, heartbeat.WorkItemQueueLatencyTrend);
                Assert.AreEqual(TimeSpan.Zero, heartbeat.WorkItemQueueLatency);

                recommendation = heartbeat.ScaleRecommendation;
                Assert.IsNotNull(recommendation);
                Assert.AreEqual(ScaleAction.None, recommendation.Action);
                Assert.AreEqual(false, recommendation.KeepWorkersAlive);
                Assert.IsNotNull(recommendation.Reason);
            }

            // If any workers are assigned, the recommendation should be to have them removed.
            heartbeat = await monitor.PulseAsync(currentWorkerCount : 1);

            recommendation = heartbeat.ScaleRecommendation;
            Assert.IsNotNull(recommendation);
            Assert.AreEqual(ScaleAction.RemoveWorker, recommendation.Action);
            Assert.AreEqual(false, recommendation.KeepWorkersAlive);
            Assert.IsNotNull(recommendation.Reason);
        }
Exemple #22
0
        /// <summary>
        /// Internal initialization call from the WebJobs host.
        /// </summary>
        /// <param name="context">Extension context provided by WebJobs.</param>
        void IExtensionConfigProvider.Initialize(ExtensionConfigContext context)
        {
            ConfigureLoaderHooks();

            // Functions V1 has it's configuration initialized at startup time (now).
            // For Functions V2 (and for some unit tests) configuration happens earlier in the pipeline.
            if (!this.isOptionsConfigured)
            {
                this.InitializeForFunctionsV1(context);
            }

            if (this.nameResolver.TryResolveWholeString(this.Options.HubName, out string taskHubName))
            {
                // use the resolved task hub name
                this.Options.HubName = taskHubName;
            }

            // Throw if any of the configured options are invalid
            this.Options.Validate();

            // For 202 support
            if (this.Options.NotificationUrl == null)
            {
#pragma warning disable CS0618 // Type or member is obsolete
                this.Options.NotificationUrl = context.GetWebhookHandler();
#pragma warning restore CS0618 // Type or member is obsolete
            }

            this.TraceConfigurationSettings();

            var bindings = new BindingHelper(this, this.TraceHelper);

            // Note that the order of the rules is important
            var rule = context.AddBindingRule <OrchestrationClientAttribute>()
                       .AddConverter <string, StartOrchestrationArgs>(bindings.StringToStartOrchestrationArgs)
                       .AddConverter <JObject, StartOrchestrationArgs>(bindings.JObjectToStartOrchestrationArgs)
                       .AddConverter <DurableOrchestrationClient, string>(bindings.DurableOrchestrationClientToString);

            rule.BindToCollector <StartOrchestrationArgs>(bindings.CreateAsyncCollector);
            rule.BindToInput <DurableOrchestrationClient>(this.GetClient);

            context.AddBindingRule <OrchestrationTriggerAttribute>()
            .BindToTrigger(new OrchestrationTriggerAttributeBindingProvider(this, context, this.TraceHelper));

            context.AddBindingRule <ActivityTriggerAttribute>()
            .BindToTrigger(new ActivityTriggerAttributeBindingProvider(this, context, this.TraceHelper));

            this.orchestrationServiceSettings = this.GetOrchestrationServiceSettings();
            this.orchestrationService         = new AzureStorageOrchestrationService(this.orchestrationServiceSettings);
            this.taskHubWorker = new TaskHubWorker(this.orchestrationService, this, this);
            this.taskHubWorker.AddOrchestrationDispatcherMiddleware(this.OrchestrationMiddleware);
        }
        public static Task DeleteTaskHubResources(string testName, bool enableExtendedSessions)
        {
            string hubName  = GetTaskHubNameFromTestName(testName, enableExtendedSessions);
            var    settings = new AzureStorageOrchestrationServiceSettings
            {
                TaskHubName             = hubName,
                StorageConnectionString = GetStorageConnectionString(),
            };

            var service = new AzureStorageOrchestrationService(settings);

            return(service.DeleteAsync());
        }
        /// <summary>
        /// Gets a <see cref="DurableOrchestrationClient"/> using configuration from a <see cref="OrchestrationClientAttribute"/> instance.
        /// </summary>
        /// <param name="attribute">The attribute containing the client configuration parameters.</param>
        /// <returns>Returns a <see cref="DurableOrchestrationClient"/> instance. The returned instance may be a cached instance.</returns>
        protected internal virtual DurableOrchestrationClient GetClient(OrchestrationClientAttribute attribute)
        {
            DurableOrchestrationClient client = this.cachedClients.GetOrAdd(
                attribute,
                attr =>
            {
                AzureStorageOrchestrationServiceSettings settings = this.GetOrchestrationServiceSettings(attr);
                var innerClient = new AzureStorageOrchestrationService(settings);
                return(new DurableOrchestrationClient(innerClient, this, attr, this.traceHelper));
            });

            return(client);
        }
        public DurabilityProvider GetDurabilityProvider()
        {
            this.EnsureInitialized();
            if (this.defaultStorageProvider == null)
            {
                var defaultService = new AzureStorageOrchestrationService(this.defaultSettings);
                this.defaultStorageProvider = new AzureStorageDurabilityProvider(
                    defaultService,
                    this.defaultConnectionName,
                    this.azureStorageOptions);
            }

            return(this.defaultStorageProvider);
        }
        public SafePartitionManager(
            AzureStorageOrchestrationService service,
            AzureStorageClient azureStorageClient,
            OrchestrationSessionManager sessionManager)
        {
            this.service            = service;
            this.azureStorageClient = azureStorageClient;
            this.settings           = this.azureStorageClient.Settings;
            this.sessionManager     = sessionManager;

            this.intentLeaseManager = AzureStorageOrchestrationService.GetBlobLeaseManager(
                this.azureStorageClient,
                "intent");

            this.intentLeaseCollectionManager = new LeaseCollectionBalancer <BlobLease>(
                "intent",
                settings,
                this.azureStorageClient.BlobAccountName,
                this.intentLeaseManager,
                new LeaseCollectionBalancerOptions
            {
                AcquireInterval = settings.LeaseAcquireInterval,
                RenewInterval   = settings.LeaseRenewInterval,
                LeaseInterval   = settings.LeaseInterval,
            });

            var currentlyOwnedIntentLeases = this.intentLeaseCollectionManager.GetCurrentlyOwnedLeases();

            this.ownershipLeaseManager = AzureStorageOrchestrationService.GetBlobLeaseManager(
                this.azureStorageClient,
                "ownership");

            this.ownershipLeaseCollectionManager = new LeaseCollectionBalancer <BlobLease>(
                "ownership",
                this.settings,
                this.azureStorageClient.BlobAccountName,
                this.ownershipLeaseManager,
                new LeaseCollectionBalancerOptions
            {
                AcquireInterval   = TimeSpan.FromSeconds(5),
                RenewInterval     = TimeSpan.FromSeconds(10),
                LeaseInterval     = TimeSpan.FromSeconds(15),
                ShouldStealLeases = false
            },
                shouldAquireLeaseDelegate: leaseKey => currentlyOwnedIntentLeases.ContainsKey(leaseKey),
                shouldRenewLeaseDelegate: leaseKey => currentlyOwnedIntentLeases.ContainsKey(leaseKey) ||
                this.sessionManager.IsControlQueueReceivingMessages(leaseKey) ||
                this.sessionManager.IsControlQueueProcessingMessages(leaseKey));
        }
Exemple #27
0
        /// <inheritdoc />
        public override async Task <IList <DurableOrchestrationStatus> > GetStatusAsync(DateTime createdTimeFrom, DateTime?createdTimeTo, IEnumerable <OrchestrationRuntimeStatus> runtimeStatus, CancellationToken cancellationToken = default(CancellationToken))
        {
            // TODO this cast is to avoid to change DurableTask.Core. Change it to use TaskHubClient.
            AzureStorageOrchestrationService serviceClient = (AzureStorageOrchestrationService)this.client.ServiceClient;
            IList <OrchestrationState>       states        = await serviceClient.GetOrchestrationStateAsync(createdTimeFrom, createdTimeTo, runtimeStatus.Select(x => (OrchestrationStatus)x), cancellationToken);

            var results = new List <DurableOrchestrationStatus>();

            foreach (OrchestrationState state in states)
            {
                results.Add(this.ConvertFrom(state));
            }

            return(results);
        }
Exemple #28
0
        /// <inheritdoc />
        public override async Task <IList <DurableOrchestrationStatus> > GetStatusAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            // TODO this cast is to avoid to change DurableTask.Core. Change it to use TaskHubClient.
            AzureStorageOrchestrationService serviceClient = (AzureStorageOrchestrationService)this.client.ServiceClient;
            IList <OrchestrationState>       states        = await serviceClient.GetOrchestrationStateAsync(cancellationToken);

            var results = new List <DurableOrchestrationStatus>();

            foreach (OrchestrationState state in states)
            {
                results.Add(this.ConvertFrom(state));
            }

            return(results);
        }
 public AzureStorageDurabilityProvider(
     AzureStorageOrchestrationService service,
     string connectionName,
     AzureStorageOptions options)
     : base("Azure Storage", service, service, connectionName)
 {
     this.serviceClient      = service;
     this.connectionName     = connectionName;
     this.storageOptionsJson = JObject.FromObject(
         options,
         new JsonSerializer
     {
         Converters       = { new StringEnumConverter() },
         ContractResolver = new CamelCasePropertyNamesContractResolver(),
     });
 }
Exemple #30
0
        public virtual DurabilityProvider GetDurabilityProvider()
        {
            this.EnsureDefaultClientSettingsInitialized();
            if (this.defaultStorageProvider == null)
            {
                var     defaultService = new AzureStorageOrchestrationService(this.defaultSettings);
                ILogger logger         = this.loggerFactory.CreateLogger(LoggerName);
                this.defaultStorageProvider = new AzureStorageDurabilityProvider(
                    defaultService,
                    this.defaultConnectionName,
                    this.azureStorageOptions,
                    logger);
            }

            return(this.defaultStorageProvider);
        }