/// <summary> /// This requests FE to add a worker. /// - FE returns success if new worker is assigned. /// - FE returns 404 No Capacity if no capacity and we will try on other stamps. /// - Other than that throws. /// </summary> public async Task <string> AddWorker(string activityId, IEnumerable <string> stampNames, int workers) { var list = stampNames.ToList(); // always scale home stamp first list.Remove(AppServiceSettings.HomeStampName); list.Insert(0, AppServiceSettings.HomeStampName); foreach (var stampName in list) { var stampHostName = GetStampHostName(stampName); var worker = new AppServiceWorkerInfo { PartitionKey = AppServiceSettings.SiteName, StampName = stampName, WorkerName = string.Empty }; var details = string.Format("Add worker request from {0}:{1}", AppServiceSettings.CurrentStampName, AppServiceSettings.WorkerName); var pathAndQuery = string.Format("https://{0}/operations/addworker/{1}?token={2}&workers={3}", stampHostName, AppServiceSettings.SiteName, GetToken(), workers); using (var response = await SendAsync(activityId, HttpMethod.Post, pathAndQuery, worker, details)) { try { response.EnsureSuccessStatusCode(); return(stampName); } catch (HttpRequestException) { // No capicity on this stamp if (response.StatusCode == HttpStatusCode.NotFound && string.Equals(response.ReasonPhrase, NoCapacity, StringComparison.OrdinalIgnoreCase)) { // try other stamps continue; } throw; } } } // already try all stamps and still no capacity return(null); }
public async Task SetManager(IWorkerInfo worker) { // update manager row var entity = new AppServiceWorkerInfo { PartitionKey = AppServiceSettings.ManagerPartitionKey, RowKey = AppServiceSettings.ManagerRowKey, StampName = worker.StampName, WorkerName = worker.WorkerName, ETag = "*" }; var operation = TableOperation.InsertOrReplace(entity); var table = await GetWorkerCloudTable(); await table.ExecuteAsync(operation); }