From 1c17a5d2beceec8ef4184362043883a69d1fc5f1 Mon Sep 17 00:00:00 2001 From: moonleay Date: Thu, 5 Oct 2023 11:39:23 +0200 Subject: [PATCH] feat: added cacheUpdateJobs Signed-off-by: moonleay --- ...atoon3ApiFestivalAndCoopUpdateScheduler.kt | 50 +++++++++++++++++++ .../Splatoon3ApiScheduleUpdateScheduler.kt | 48 ++++++++++++++++++ ...Splatoon3ApiSplatnetGearUpdateScheduler.kt | 47 +++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 src/main/kotlin/net/moonleay/lilJudd/jobs/Splatoon3ApiFestivalAndCoopUpdateScheduler.kt create mode 100644 src/main/kotlin/net/moonleay/lilJudd/jobs/Splatoon3ApiScheduleUpdateScheduler.kt create mode 100644 src/main/kotlin/net/moonleay/lilJudd/jobs/Splatoon3ApiSplatnetGearUpdateScheduler.kt diff --git a/src/main/kotlin/net/moonleay/lilJudd/jobs/Splatoon3ApiFestivalAndCoopUpdateScheduler.kt b/src/main/kotlin/net/moonleay/lilJudd/jobs/Splatoon3ApiFestivalAndCoopUpdateScheduler.kt new file mode 100644 index 0000000..8e05cb1 --- /dev/null +++ b/src/main/kotlin/net/moonleay/lilJudd/jobs/Splatoon3ApiFestivalAndCoopUpdateScheduler.kt @@ -0,0 +1,50 @@ +/* + * lilJudd + * Copyright (C) 2023 moonleay + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.moonleay.lilJudd.jobs + +import dev.inmo.krontab.KronScheduler +import kotlinx.coroutines.Job +import net.moonleay.lilJudd.data.api.Splatoon3ApiCache +import net.moonleay.lilJudd.data.api.type.ApiDataType +import net.moonleay.lilJudd.data.api.type.ApiRequestType +import net.moonleay.lilJudd.jobs.component.CronjobType +import net.moonleay.lilJudd.jobs.component.ICronjob +import net.moonleay.lilJudd.util.Logger + +object Splatoon3ApiFestivalAndCoopUpdateScheduler : ICronjob { + override val jobName: String + get() = "Splatoon3ApiFestivalAndCoopUpdateScheduler" + override val jobIncoming: String + get() = "0 0 0 /1 *" // once a day + override val jobType: CronjobType + get() = CronjobType.INFINITE + override val continueJob: Boolean + get() = true + override lateinit var cronjobJob: Job + override lateinit var scheduler: KronScheduler + + override suspend fun jobFunction() { + Logger.out("Running Splatoon3ApiFestivalUpdateScheduler.") + Splatoon3ApiCache.updateData(ApiDataType.SPLATFESTS, ApiRequestType.AUTOMATIC_CACHE_UPDATE) + Logger.out("Splatoon3ApiFestivalUpdateScheduler finished.") + Logger.out("Running Splatoon3ApiCoopUpdateScheduler.") + Splatoon3ApiCache.updateData(ApiDataType.COOP, ApiRequestType.AUTOMATIC_CACHE_UPDATE) + Logger.out("Splatoon3ApiCoopUpdateScheduler finished.") + } +} diff --git a/src/main/kotlin/net/moonleay/lilJudd/jobs/Splatoon3ApiScheduleUpdateScheduler.kt b/src/main/kotlin/net/moonleay/lilJudd/jobs/Splatoon3ApiScheduleUpdateScheduler.kt new file mode 100644 index 0000000..70d7c58 --- /dev/null +++ b/src/main/kotlin/net/moonleay/lilJudd/jobs/Splatoon3ApiScheduleUpdateScheduler.kt @@ -0,0 +1,48 @@ +/* + * lilJudd + * Copyright (C) 2023 moonleay + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.moonleay.lilJudd.jobs + +import dev.inmo.krontab.KronScheduler +import kotlinx.coroutines.Job +import net.moonleay.lilJudd.data.api.Splatoon3ApiCache +import net.moonleay.lilJudd.data.api.type.ApiDataType +import net.moonleay.lilJudd.data.api.type.ApiRequestType +import net.moonleay.lilJudd.jobs.component.CronjobType +import net.moonleay.lilJudd.jobs.component.ICronjob +import net.moonleay.lilJudd.util.Logger + +object Splatoon3ApiScheduleUpdateScheduler : ICronjob { + override val jobName: String + get() = "Splatoon3ApiScheduleUpdateScheduler" + override val jobIncoming: String + get() = "0 /30 * * *" //Every 30 minutes + override val jobType: CronjobType + get() = CronjobType.INFINITE + override val continueJob: Boolean + get() = true + override lateinit var cronjobJob: Job + override lateinit var scheduler: KronScheduler + + override suspend fun jobFunction() { + Logger.out("Running Splatoon3ApiScheduleUpdateScheduler.") + Splatoon3ApiCache.updateData(ApiDataType.SCHEDULES, ApiRequestType.AUTOMATIC_CACHE_UPDATE) + StatusUpdater.refreshStatusList(System.currentTimeMillis()) + Logger.out("Splatoon3ApiScheduleUpdateScheduler finished.") + } +} diff --git a/src/main/kotlin/net/moonleay/lilJudd/jobs/Splatoon3ApiSplatnetGearUpdateScheduler.kt b/src/main/kotlin/net/moonleay/lilJudd/jobs/Splatoon3ApiSplatnetGearUpdateScheduler.kt new file mode 100644 index 0000000..3db9fda --- /dev/null +++ b/src/main/kotlin/net/moonleay/lilJudd/jobs/Splatoon3ApiSplatnetGearUpdateScheduler.kt @@ -0,0 +1,47 @@ +/* + * lilJudd + * Copyright (C) 2023 moonleay + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.moonleay.lilJudd.jobs + +import dev.inmo.krontab.KronScheduler +import kotlinx.coroutines.Job +import net.moonleay.lilJudd.data.api.Splatoon3ApiCache +import net.moonleay.lilJudd.data.api.type.ApiDataType +import net.moonleay.lilJudd.data.api.type.ApiRequestType +import net.moonleay.lilJudd.jobs.component.CronjobType +import net.moonleay.lilJudd.jobs.component.ICronjob +import net.moonleay.lilJudd.util.Logger + +object Splatoon3ApiSplatnetGearUpdateScheduler : ICronjob { + override val jobName: String + get() = "Splatoon3ApiSplatnetGearUpdateScheduler" + override val jobIncoming: String + get() = "* * /6 * *" //Every 6 hours + override val jobType: CronjobType + get() = CronjobType.INFINITE + override val continueJob: Boolean + get() = true + override lateinit var cronjobJob: Job + override lateinit var scheduler: KronScheduler + + override suspend fun jobFunction() { + Logger.out("Running Splatoon3ApiSplatnetGearUpdateScheduler.") + Splatoon3ApiCache.updateData(ApiDataType.SPLATNETGEAR, ApiRequestType.AUTOMATIC_CACHE_UPDATE) + Logger.out("Splatoon3ApiSplatnetGearUpdateScheduler finished.") + } +}