Example #1
0
 private void MaybeGroomPocketed(CancellationToken ct)
 {
     if (DateTime.UtcNow > _groomSchedule)
     {
         AzureStorageAssistant.GroomOldBlobsFrom(_containerName, oldMessage, ct);
         _groomSchedule = DateTime.UtcNow + TimeSpan.FromHours(1.0);
     }
 }
Example #2
0
        public AzureEnvironmentDistributedMutex()
        {
            _log   = ClassLogger.Create(GetType());
            _dblog = DebugOnlyLogger.Create(_log);

            var config = Catalog.Factory.Resolve <IConfig>(SpecialFactoryContexts.Routed);

            _name         = config[DistributedMutexLocalConfig.Name].ToLowerInvariant();
            _expireUnused = TimeSpan.FromSeconds(config.Get <int>(DistributedMutexLocalConfig.UnusedExpirationSeconds));

            var account = Client.FromConfig().ForBlobs();

            _container = account.GetContainerReference(AzureConstants.LeaseContainer);
            _container.CreateIfNotExist();

            _leaseBlob = _container.GetBlobReference(_name);

            _cts            = new CancellationTokenSource();
            _cancelGrooming = new CancellationTokenSource();

            try
            {
                if (!_leaseBlob.Exists())
                {
                    _leaseBlob.UploadText("1");
                    _leaseBlob.SetExpiration(_expireUnused);

                    _log.InfoFormat("Creating distributed mutex for {0}, auto expires in {1}", _name, _expireUnused);
                }
            }
            catch (StorageClientException storageClientException1)
            {
                StorageClientException storageClientException = storageClientException1;
                if (storageClientException.ErrorCode == StorageErrorCode.BlobAlreadyExists ||
                    storageClientException.StatusCode == HttpStatusCode.PreconditionFailed)
                {
                }
                else
                {
                    throw;
                }
            }


            _groomingTask =
                Task.Factory.StartNew(
                    () =>
                    AzureStorageAssistant.CleanExpiredBlobsFrom(AzureConstants.LeaseContainer, _cancelGrooming.Token,
                                                                false));
        }
Example #3
0
        /// <summary>
        ///   searches for and deletes all blobs marked as expired
        /// </summary>
        /// <param name="ct"> </param>
        private static void CleanExpiredBlobs(CancellationToken ct)
        {
            try
            {
                var account =
                    CloudStorageAccount.FromConfigurationSetting(CommonConfiguration.DefaultStorageConnection.ToString());
                var bc = account.CreateCloudBlobClient();

                ct.ThrowIfCancellationRequested();
                var containers = bc.ListContainers();

                foreach (var c in containers)
                {
                    ct.ThrowIfCancellationRequested();
                    AzureStorageAssistant.CleanExpiredBlobsFrom(c.Name, ct);
                }
            }
            catch
            {
            }
        }
Example #4
0
 /// <summary>
 ///   Deletes any blob containers marked as expired
 /// </summary>
 /// <param name="ct"> </param>
 private static void CleanExpiredContainers(CancellationToken ct)
 {
     AzureStorageAssistant.GroomExpiredContainers();
 }
Example #5
0
 /// <summary>
 ///   Searches the blob upload folder for uploads that are too old to complete, and deletes them.
 /// </summary>
 /// <param name="ct"> </param>
 private static void CleanUploads(CancellationToken ct)
 {
     AzureStorageAssistant.GroomOldBlobsFrom(BlobBufferedFileUpload.UploadBufferContainer,
                                             TimeSpan.FromDays(30.0), ct);
 }