Add scheduling

This commit is contained in:
Ryan Harg 2024-02-12 11:54:42 +01:00
parent 16a0740679
commit 1c59227030
2 changed files with 11 additions and 3 deletions

View file

@ -1,13 +1,15 @@
package de.rpr.githubreleases package de.rpr.githubreleases
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
fun main() { fun main() {
val config = Config() val config = Config()
val publishers = Publishers(config) val publishers = Publishers(config)
val releaseRepository = ReleaseRepository() val releaseRepository = ReleaseRepository()
val app = App(config, releaseRepository, OkHttpClient(), publishers) val app = App(config, releaseRepository, OkHttpClient(), publishers)
app.execute() app.schedule()
} }
class App( class App(
@ -17,7 +19,13 @@ class App(
private val publishers: Publishers 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 -> config.githubRepos.forEach { githubRepo ->
val existingReleases = releaseRepo.getExistingReleases(githubRepo) val existingReleases = releaseRepo.getExistingReleases(githubRepo)

View file

@ -17,7 +17,7 @@ class Config {
validate() validate()
} }
fun validate() { private fun validate() {
if (instanceUrl.isNullOrBlank()) { if (instanceUrl.isNullOrBlank()) {
ERROR.log("No instance url available, please set the environment variable $instanceUrlEnvName") ERROR.log("No instance url available, please set the environment variable $instanceUrlEnvName")
valid = false valid = false