EvaluateShards() { // Get the send queue shard. var sendShard = this.queueShardMonitor.SendShard; if (sendShard == null) { var firstShardName = SlinqyQueueShard.GenerateFirstShardName( this.queueShardMonitor.QueueName, this.shardIndexPadding ); await this.queueService .CreateQueue(firstShardName) .ConfigureAwait(false); } else { // Scale if needed. if (sendShard.StorageUtilization > this.storageCapacityScaleOutThreshold) { await this.ScaleOut(sendShard).ConfigureAwait(false); } // Make sure shard states are set properly. await this.SetShardStates() .ConfigureAwait( false); } // Finally queue it all to happen again! await this.agentQueue .Send(new EvaluateShardsCommand(), DateTimeOffset.UtcNow.AddSeconds(5)) .ConfigureAwait(false); }
CreateQueueAsync( string queueName, int shardIndexPadding) { // TODO: Refactor - Much of this functionality overlaps with the Agent, // let Agent create first shard too and remove this code. if (string.IsNullOrWhiteSpace(queueName)) { throw new ArgumentNullException(nameof(queueName)); } var queueShardName = SlinqyQueueShard.GenerateFirstShardName( slinqyQueueName: queueName, shardIndexPadding: shardIndexPadding ); // Call the function to create the first physical queue shard to establish the virtual queue. // No need to do anything with the returned shard... var shard = await this.physicalQueueService .CreateQueue(queueShardName) .ConfigureAwait(false); var shardMonitor = new SlinqyQueueShardMonitor( queueName, this.physicalQueueService ); await shardMonitor .Start() .ConfigureAwait(false); var queue = new SlinqyQueue( shardMonitor ); this.slinqyQueues.TryAdd(queueName, queue); return(queue); }