Skip to content

Commit

Permalink
Fix job retry counter increment in FastJobStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
valldrac committed Sep 7, 2024
1 parent 8a1bdc4 commit b342b50
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ class FastJobStorage(private val jobDatabase: JobDatabase) : JobStorage {
jobDatabase.updateJobAfterRetry(id, currentTime, runAttempt, nextBackoffInterval, serializedData)

// Note: All other fields are accounted for in the min spec. We only need to update from disk if serialized data changes.
val cached = jobSpecCache[id]
if (cached != null && !cached.serializedData.contentEquals(serializedData)) {
jobDatabase.getJobSpec(id)?.let {
jobSpecCache[id] = it
}
jobSpecCache.computeIfPresent(id) { _, cached ->
if (cached.serializedData.contentEquals(serializedData))
cached.copy(runAttempt = runAttempt)
else
jobDatabase.getJobSpec(id)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,15 @@ class FastJobStorageTest {

@Test
fun `updateJobAfterRetry - state updated`() {
val fullSpec = FullSpec(jobSpec(id = "1", factoryKey = "f1", isRunning = true), emptyList(), emptyList())
val fullSpec = FullSpec(jobSpec(id = "1", factoryKey = "f1", isRunning = true, serializedData = "a".toByteArray()), emptyList(), emptyList())

val subject = FastJobStorage(mockDatabase(listOf(fullSpec)))
subject.init()

subject.updateJobAfterRetry(
id = "1",
currentTime = 3,
runAttempt = 1,
runAttempt = 2,
nextBackoffInterval = 10,
serializedData = "a".toByteArray()
)
Expand All @@ -315,7 +315,7 @@ class FastJobStorageTest {
check(job != null)
job.isRunning assertIs false
job.lastRunAttemptTime assertIs 3
job.runAttempt assertIs 1
job.runAttempt assertIs 2
job.nextBackoffInterval assertIs 10
job.serializedData!!.toString(Charset.defaultCharset()) assertIs "a"
}
Expand Down

0 comments on commit b342b50

Please sign in to comment.