internal async Task AcquireAsync(ActorTableEntityOptions options = null) { var blobReference = await GetBlobReference(); if (!await blobReference.ExistsAsync()) { await blobReference.UploadTextAsync(string.Empty); } try { if (options?.WithRetry == true) { leaseId = await Do(() => blobReference.AcquireLeaseAsync(TimeSpan.FromMilliseconds(options.RetryIntervalMilliseconds))); } else { leaseId = await blobReference.AcquireLeaseAsync(TimeSpan.FromSeconds(60)); } } catch (StorageException ex) when(ex.RequestInformation.HttpStatusCode == (int)HttpStatusCode.Conflict) { throw new InvalidOperationException($"Another job is already running for {key}."); } }
public static void Initialise(ActorTableEntityOptions options) { Settings = options; if (Settings == null) { return; } if (Settings.StorageConnectionString == null) { throw new ArgumentNullException(nameof(Settings.StorageConnectionString)); } if (Settings.ContainerName == null) { throw new ArgumentNullException(nameof(Settings.ContainerName)); } var storageAccount = CloudStorageAccount.Parse(Settings.StorageConnectionString); BlobClient = storageAccount.CreateCloudBlobClient(); }