/// <remarks> /// Logs exceptions, hence failing to handle a task fault at the calling side /// will not cause an unhandled exception at finalization /// </remarks> Task <int> GetWorkerInstanceCount(CancellationToken cancellationToken) { var task = _provisioning.GetCurrentLokadCloudWorkerCount(_currentDeployment, cancellationToken); // TODO (ruegg, 2011-05-30): Replace with system events task.ContinueWith(t => { try { if (t.IsFaulted) { if (ProvisioningErrorHandling.IsTransientError(t.Exception)) { _log.TryDebug("Provisioning: Getting the current worker instance count failed with a transient error.", task.Exception.GetBaseException()); } else { _log.TryWarn("Provisioning: Getting the current worker instance count failed with a permanent error.", task.Exception.GetBaseException()); } } } catch (Exception) { // We don't really care, it's only logging that failed } }, TaskContinuationOptions.ExecuteSynchronously); return(task); }
/// <remarks> /// Logs exceptions, hence failing to handle a task fault at the calling side /// will not cause an unhandled exception at finalization /// </remarks> Task SetWorkerInstanceCount(int count, CancellationToken cancellationToken) { if (count <= 0 && count > 500) { throw new ArgumentOutOfRangeException("count"); } var task = _provisioning.UpdateCurrentLokadCloudWorkerCount(_currentDeployment, count, cancellationToken); // TODO (ruegg, 2011-05-30): Replace with system events task.ContinueWith(t => { try { if (t.IsFaulted) { HttpStatusCode httpStatus; if (ProvisioningErrorHandling.TryGetHttpStatusCode(t.Exception, out httpStatus)) { switch (httpStatus) { case HttpStatusCode.Conflict: _log.TryDebugFormat("Provisioning: Updating the worker instance count to {0} failed because another deployment update is already in progress.", count); break; default: _log.TryDebugFormat("Provisioning: Updating the worker instance count failed with HTTP Status {0} ({1}).", httpStatus, (int)httpStatus); break; } } else if (ProvisioningErrorHandling.IsTransientError(t.Exception)) { _log.TryDebug("Provisioning: Updating the worker instance count failed with a transient error.", task.Exception.GetBaseException()); } else { _log.TryWarn("Provisioning: Updating the worker instance count failed with a permanent error.", task.Exception.GetBaseException()); } } } catch (Exception) { // We don't really care, it's only logging that failed } }, TaskContinuationOptions.ExecuteSynchronously); return(task); }