From 1c59227030ccae58962e870251ed00722bee16b0 Mon Sep 17 00:00:00 2001 From: Ryan Harg Date: Mon, 12 Feb 2024 11:54:42 +0100 Subject: [PATCH] Add scheduling --- app/src/main/kotlin/de/rpr/githubreleases/App.kt | 12 ++++++++++-- app/src/main/kotlin/de/rpr/githubreleases/Config.kt | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/de/rpr/githubreleases/App.kt b/app/src/main/kotlin/de/rpr/githubreleases/App.kt index d2145b1..95f9424 100644 --- a/app/src/main/kotlin/de/rpr/githubreleases/App.kt +++ b/app/src/main/kotlin/de/rpr/githubreleases/App.kt @@ -1,13 +1,15 @@ package de.rpr.githubreleases import okhttp3.OkHttpClient +import java.util.concurrent.Executors +import java.util.concurrent.TimeUnit fun main() { val config = Config() val publishers = Publishers(config) val releaseRepository = ReleaseRepository() val app = App(config, releaseRepository, OkHttpClient(), publishers) - app.execute() + app.schedule() } class App( @@ -17,7 +19,13 @@ class App( private val publishers: Publishers ) { - fun execute() { + fun schedule() { + log("Scheduling app...") + val executor = Executors.newSingleThreadScheduledExecutor() + executor.scheduleAtFixedRate({ execute() }, 5, config.schedulingDelay, TimeUnit.SECONDS) + } + + private fun execute() { config.githubRepos.forEach { githubRepo -> val existingReleases = releaseRepo.getExistingReleases(githubRepo) diff --git a/app/src/main/kotlin/de/rpr/githubreleases/Config.kt b/app/src/main/kotlin/de/rpr/githubreleases/Config.kt index af1ddaf..cab906f 100644 --- a/app/src/main/kotlin/de/rpr/githubreleases/Config.kt +++ b/app/src/main/kotlin/de/rpr/githubreleases/Config.kt @@ -17,7 +17,7 @@ class Config { validate() } - fun validate() { + private fun validate() { if (instanceUrl.isNullOrBlank()) { ERROR.log("No instance url available, please set the environment variable $instanceUrlEnvName") valid = false