Skip to content

Commit

Permalink
[webhooks] refactor retry condition
Browse files Browse the repository at this point in the history
  • Loading branch information
capcom6 committed Jun 23, 2024
1 parent d9379e6 commit c73a4bf
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class SendWebhookWorker(appContext: Context, params: WorkerParameters) :

override suspend fun doWork(): Result {
try {
if (runAttemptCount >= MAX_RETRIES) {
return Result.failure()
}

val url = inputData.getString(INPUT_URL) ?: return Result.failure()
val deviceId = inputData.getString(INPUT_DEVICE_ID) ?: return Result.failure()
val event = inputData.getString(INPUT_EVENT)?.let { WebHookEvent.valueOf(it) }
Expand All @@ -65,10 +69,7 @@ class SendWebhookWorker(appContext: Context, params: WorkerParameters) :
return Result.failure()
} catch (e: Throwable) {
e.printStackTrace()
return when (runAttemptCount >= MAX_RETRIES) {
false -> Result.retry()
else -> Result.failure()
}
return Result.retry()
} finally {
client.close()
}
Expand Down

0 comments on commit c73a4bf

Please sign in to comment.