override fun canStartNewInstance()

in plugin-azure-server/src/main/kotlin/jetbrains/buildServer/clouds/azure/arm/AzureCloudImage.kt [83:100]


    override fun canStartNewInstance(): CanStartNewInstanceResult {
        if (activeInstances.size >= myImageDetails.maxInstances) {
            return CanStartNewInstanceResult.no("Quota exceeded: ActiveInstances count reached MaxInstances value of ${myImageDetails.maxInstances}")
        }
        // Check Azure CPU quota state
        azureCpuQuotaExceeded?.let { instances ->
            if (instances == getInstanceIds()) {
                return CanStartNewInstanceResult.no("Azure CPU quota exceeded")
            } else {
                azureCpuQuotaExceeded = null
                LOG.info("Azure CPU quota limit has been reset due to change in the number of active instances for image ${imageDetails.sourceId}.")
            }
        }
        if (imageDetails.deployTarget == AzureCloudDeployTarget.Instance && stoppedInstances.isEmpty()) {
            return CanStartNewInstanceResult.no("Stopped Instances pool is empty, but we trying to run yet another instance. Check inactive agents for errors")
        }
        return CanStartNewInstanceResult.yes()
    }