Skip to content

Commit

Permalink
add job deletion for succeded and failed jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
psuzn committed May 26, 2024
1 parent 08b8b09 commit 796451b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.sujanpoudel.playdeals

import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
Expand Down Expand Up @@ -129,7 +130,8 @@ fun configureDI(
.useJobActivator(instance())
.useBackgroundJobServer(
BackgroundJobServerConfiguration.usingStandardBackgroundJobServerConfiguration()
.andDeleteSucceededJobsAfter(Duration.ofHours(6))
.andDeleteSucceededJobsAfter(Duration.ofMinutes(10))
.andPermanentlyDeleteDeletedJobsAfter(Duration.ofMinutes(10))
.andWorkerCount(1)
.andPollIntervalInSeconds(10)
)
Expand All @@ -154,7 +156,8 @@ fun configureDI(
bindSingleton {
AndroidAppExpiryCheckScheduler(
repository = instance(),
requestScheduler = instance()
requestScheduler = instance(),
storageProvider = instance()
)
}
bindSingleton {
Expand Down Expand Up @@ -193,5 +196,6 @@ private fun configureObjectMapper(): ObjectMapper {
registerKotlinModule()
registerModule(JavaTimeModule())
configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@ package me.sujanpoudel.playdeals.jobs

import me.sujanpoudel.playdeals.common.SIMPLE_NAME
import me.sujanpoudel.playdeals.common.loggingExecutionTime
import me.sujanpoudel.playdeals.logger
import me.sujanpoudel.playdeals.repositories.DealRepository
import org.jobrunr.jobs.lambdas.JobRequest
import org.jobrunr.jobs.states.StateName
import org.jobrunr.scheduling.JobRequestScheduler
import org.jobrunr.scheduling.RecurringJobBuilder
import org.jobrunr.storage.StorageProvider
import java.time.Duration
import java.time.Instant
import java.time.temporal.ChronoUnit
import java.util.UUID

class AndroidAppExpiryCheckScheduler(
private val repository: DealRepository,
private val requestScheduler: JobRequestScheduler
private val requestScheduler: JobRequestScheduler,
private val storageProvider: StorageProvider
) : CoJobRequestHandler<AndroidAppExpiryCheckScheduler.Request>() {

override suspend fun handleRequest(jobRequest: Request): Unit = loggingExecutionTime(
Expand All @@ -21,6 +27,10 @@ class AndroidAppExpiryCheckScheduler(
.map { AppDetailScrapper.Request(it.id) }

requestScheduler.enqueue(apps)

val lastUpdatedTime = Instant.now().minus(1, ChronoUnit.HOURS)
val jobs = storageProvider.deleteJobsPermanently(StateName.FAILED, lastUpdatedTime)
logger.info("deleted FAILED `$jobs`")
}

class Request private constructor() : JobRequest {
Expand Down

0 comments on commit 796451b

Please sign in to comment.