Skip to content

Commit 910e4da

Browse files
committed
[webhooks] add webhooks retry count option, see #125
1 parent bd7e5b5 commit 910e4da

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

app/src/main/java/me/capcom/smsgateway/modules/webhooks/WebhooksSettings.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ class WebhooksSettings(
99
val internetRequired: Boolean
1010
get() = storage.get<Boolean>(INTERNET_REQUIRED) ?: true
1111

12+
val retryCount: Int
13+
get() = storage.get<Int>(RETRY_COUNT) ?: 15
14+
1215
companion object {
1316
const val INTERNET_REQUIRED = "internet_required"
17+
const val RETRY_COUNT = "retry_count"
1418
}
1519
}

app/src/main/java/me/capcom/smsgateway/modules/webhooks/workers/SendWebhookWorker.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import me.capcom.smsgateway.modules.logs.LogsService
3333
import me.capcom.smsgateway.modules.logs.db.LogEntry
3434
import me.capcom.smsgateway.modules.notifications.NotificationsService
3535
import me.capcom.smsgateway.modules.webhooks.NAME
36+
import me.capcom.smsgateway.modules.webhooks.WebhooksSettings
3637
import me.capcom.smsgateway.modules.webhooks.domain.WebHookEventDTO
3738
import org.json.JSONException
3839
import org.koin.core.component.KoinComponent
@@ -45,6 +46,8 @@ class SendWebhookWorker(appContext: Context, params: WorkerParameters) :
4546
private val notificationsSvc: NotificationsService by inject()
4647
private val logsSvc: LogsService by inject()
4748

49+
private val settings: WebhooksSettings by inject()
50+
4851
override suspend fun doWork(): ListenableWorker.Result {
4952
return when (val result = sendData()) {
5053
Result.Success -> {
@@ -91,7 +94,7 @@ class SendWebhookWorker(appContext: Context, params: WorkerParameters) :
9194

9295
private suspend fun sendData(): Result {
9396
try {
94-
if (runAttemptCount > MAX_RETRIES) {
97+
if (runAttemptCount >= settings.retryCount) {
9598
return Result.Failure("Retry limit exceeded")
9699
}
97100

@@ -203,8 +206,6 @@ class SendWebhookWorker(appContext: Context, params: WorkerParameters) :
203206

204207
private val gson = GsonBuilder().configure().create()
205208

206-
private const val MAX_RETRIES = 14
207-
208209
private const val INPUT_URL = "url"
209210
private const val INPUT_DATA = "data"
210211
}

app/src/main/java/me/capcom/smsgateway/ui/SettingsFragment.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
5050

5151
if (preference.key == "ping.interval_seconds"
5252
|| preference.key == "logs.lifetime_days"
53+
|| preference.key == "webhooks.retry_count"
5354
) {
5455
(preference as EditTextPreference).setOnBindEditTextListener {
5556
it.inputType = InputType.TYPE_CLASS_NUMBER

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,7 @@
6363
<string name="webhooks">Webhooks</string>
6464
<string name="the_webhook_request_will_wait_for_an_internet_connection">The webhook request will wait for an internet connection</string>
6565
<string name="require_internet_connection">Require Internet connection</string>
66+
<string name="more_settings">More settings...</string>
67+
<string name="delays_limits_etc">Delays, Limits, etc.</string>
68+
<string name="retry_count">Retry count</string>
6669
</resources>

app/src/main/res/xml/root_preferences.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
<PreferenceCategory app:title="@string/messages_header">
2525
<Preference
2626
app:fragment="me.capcom.smsgateway.ui.settings.MessagesSettingsFragment"
27-
app:title="More settings..." />
27+
app:title="@string/more_settings"
28+
app:summary="@string/delays_limits_etc"/>
2829
</PreferenceCategory>
2930

3031
<PreferenceCategory app:title="@string/webhooks">
@@ -33,6 +34,11 @@
3334
android:key="webhooks.internet_required"
3435
app:summary="@string/the_webhook_request_will_wait_for_an_internet_connection"
3536
app:title="@string/require_internet_connection" />
37+
<EditTextPreference
38+
android:key="webhooks.retry_count"
39+
app:title="@string/retry_count"
40+
app:defaultValue="15"
41+
app:useSimpleSummaryProvider="true" />
3642
</PreferenceCategory>
3743

3844
<PreferenceCategory

0 commit comments

Comments
 (0)