Fix runAttempt not updating in job cache.
Thank you to @valldrac for finding this and diagnosing it! Fixes #13679
This commit is contained in:
parent
7835b1d1fc
commit
cb126a2f08
2 changed files with 10 additions and 8 deletions
|
@ -200,12 +200,14 @@ class FastJobStorage(private val jobDatabase: JobDatabase) : JobStorage {
|
||||||
if (job == null || !job.isMemoryOnly) {
|
if (job == null || !job.isMemoryOnly) {
|
||||||
jobDatabase.updateJobAfterRetry(id, currentTime, runAttempt, nextBackoffInterval, serializedData)
|
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.
|
// Note: Serialized data and run attempt are the only JobSpec-specific fields that need to be updated -- the rest are in MinimalJobSpec and will be
|
||||||
|
// updated below.
|
||||||
val cached = jobSpecCache[id]
|
val cached = jobSpecCache[id]
|
||||||
if (cached != null && !cached.serializedData.contentEquals(serializedData)) {
|
if (cached != null) {
|
||||||
jobDatabase.getJobSpec(id)?.let {
|
jobSpecCache[id] = cached.copy(
|
||||||
jobSpecCache[id] = it
|
serializedData = serializedData,
|
||||||
}
|
runAttempt = runAttempt
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -298,7 +298,7 @@ class FastJobStorageTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `updateJobAfterRetry - state updated`() {
|
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)))
|
val subject = FastJobStorage(mockDatabase(listOf(fullSpec)))
|
||||||
subject.init()
|
subject.init()
|
||||||
|
@ -306,7 +306,7 @@ class FastJobStorageTest {
|
||||||
subject.updateJobAfterRetry(
|
subject.updateJobAfterRetry(
|
||||||
id = "1",
|
id = "1",
|
||||||
currentTime = 3,
|
currentTime = 3,
|
||||||
runAttempt = 1,
|
runAttempt = 2,
|
||||||
nextBackoffInterval = 10,
|
nextBackoffInterval = 10,
|
||||||
serializedData = "a".toByteArray()
|
serializedData = "a".toByteArray()
|
||||||
)
|
)
|
||||||
|
@ -315,7 +315,7 @@ class FastJobStorageTest {
|
||||||
check(job != null)
|
check(job != null)
|
||||||
job.isRunning assertIs false
|
job.isRunning assertIs false
|
||||||
job.lastRunAttemptTime assertIs 3
|
job.lastRunAttemptTime assertIs 3
|
||||||
job.runAttempt assertIs 1
|
job.runAttempt assertIs 2
|
||||||
job.nextBackoffInterval assertIs 10
|
job.nextBackoffInterval assertIs 10
|
||||||
job.serializedData!!.toString(Charset.defaultCharset()) assertIs "a"
|
job.serializedData!!.toString(Charset.defaultCharset()) assertIs "a"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue