Skip to content

Commit

Permalink
Workの状況によりタイムアウト時間を変える
Browse files Browse the repository at this point in the history
  • Loading branch information
tateisu committed Feb 11, 2023
1 parent ca876f3 commit e897265
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app/src/main/java/jp/juggler/subwaytooter/push/PushRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class PushRepo(
}
}
}
val timeout = timeSwitchStart + TimeUnit.MINUTES.toMillis(30)

while (true) {
if (PushWorker.timeEndRegisterEndpoint.get() >= timeSwitchStart ||
PushWorker.timeEndUpEndpoint.get() >= timeSwitchStart
Expand All @@ -214,11 +214,19 @@ class PushRepo(
}.flatten().filter { !it.state.isFinished }

works.map {
"work tag=${it.tags.joinToString("/")} state=${it.state} id=${it.id}"
"work tag=${
it.tags.filter { t -> !t.startsWith(PushWorker::class.java.name) }
.joinToString("/")
} state=${it.state} id=${it.id}"
}.let { lines.addAll(it) }
showProgress(lines.sorted().joinToString("\n"))

val remain = min(1000L, timeout - System.currentTimeMillis())
val timeout = when {
works.isEmpty() -> TimeUnit.MINUTES.toMillis(2)
else -> TimeUnit.MINUTES.toMillis(30)
}

val remain = min(1000L, timeSwitchStart + timeout - System.currentTimeMillis())
if (remain <= 0) {
showProgress("timeout")
delay(666L)
Expand Down Expand Up @@ -266,7 +274,7 @@ class PushRepo(
suspend fun registerEndpoint(
keepAliveMode: Boolean,
) {
if(subscriptionMutex.isLocked){
if (subscriptionMutex.isLocked) {
refReporter?.get()?.invoke("registerEndpoint: waiting mutex…")
}
subscriptionMutex.withLock {
Expand Down

0 comments on commit e897265

Please sign in to comment.