suspend fun refreshEnvironments()

in plugin/src/main/kotlin/toolbox/gateway/sample/EnvironmentRepository.kt [58:81]


  suspend fun refreshEnvironments() {
    logger.debug("Refreshing environments from ${dataSource::class.simpleName}")

    try {
      val configs = dataSource.fetchEnvironments()
      val environments = configs.map { config ->
        getOrCreateEnvironment(config)
      }

      // Remove environments that no longer exist
      val currentIds = configs.map { it.id }.toSet()
      environmentCache.keys.removeAll { it !in currentIds }

      _environments.value = LoadableState.Value(environments)
      logger.info("PLUGIN: Setting environments to ${environments.size} items: ${environments.map { it.id }}")

    } catch (e: CancellationException) {
      throw e
    } catch (e: DataSourceException) {
      logger.error("Data source error: ${e.message}")
    } catch (e: Exception) {
      logger.error("Unexpected error: ${e.message}")
    }
  }