Add check for KEEP_ALIVE job state to allow for re-submission.

This commit is contained in:
Alex Hart
2024-08-16 15:52:09 -03:00
committed by mtang-signal
parent b7e9446cde
commit 1f8481d287
3 changed files with 13 additions and 20 deletions

View File

@@ -286,19 +286,6 @@ class InAppPaymentTable(context: Context, databaseHelper: SignalDatabase) : Data
.run()
}
/**
* Returns whether there are any pending donations in the database.
*/
fun hasPending(type: InAppPaymentType): Boolean {
return readableDatabase.exists(TABLE_NAME)
.where(
"$STATE = ? AND $TYPE = ?",
State.serialize(State.PENDING),
InAppPaymentType.serialize(type)
)
.run()
}
/**
* Retrieves from the database the latest payment of the given type that is either in the PENDING or WAITING_FOR_AUTHORIZATION state.
*/

View File

@@ -47,6 +47,7 @@ class InAppPaymentKeepAliveJob private constructor(
private val TIMEOUT = 3.days
const val KEEP_ALIVE = "keep-alive"
private const val DATA_TYPE = "type"
fun create(type: InAppPaymentSubscriberRecord.Type): Job {
@@ -131,11 +132,6 @@ class InAppPaymentKeepAliveJob private constructor(
}
}
if (SignalDatabase.inAppPayments.hasPending(type.inAppPaymentType)) {
info(type, "Already trying to redeem $type. Exiting.")
return
}
val activeInAppPayment = getActiveInAppPayment(subscriber, subscription)
if (activeInAppPayment == null) {
warn(type, "Failed to generate active in-app payment. Exiting")
@@ -144,7 +140,6 @@ class InAppPaymentKeepAliveJob private constructor(
if (activeInAppPayment.state == InAppPaymentTable.State.END) {
warn(type, "Active in-app payment is in the END state. Cannot proceed.")
warn(type, "Active in-app payment error state: ${activeInAppPayment.data.error}")
warn(type, "Active in-app payment cancel state: ${activeInAppPayment.data.cancellation}")
return
}
@@ -275,6 +270,17 @@ class InAppPaymentKeepAliveJob private constructor(
MultiDeviceSubscriptionSyncRequestJob.enqueue()
SignalDatabase.inAppPayments.getById(inAppPaymentId)
} else if (current.state == InAppPaymentTable.State.PENDING && current.data.error?.data_ == KEEP_ALIVE) {
info(type, "Found failed keep-alive. Retrying.")
SignalDatabase.inAppPayments.update(
current.copy(
data = current.data.copy(
error = null
)
)
)
SignalDatabase.inAppPayments.getById(current.id)
} else {
current
}

View File

@@ -247,7 +247,7 @@ class InAppPaymentRecurringContextJob private constructor(
data = inAppPayment.data.copy(
error = InAppPaymentData.Error(
type = InAppPaymentData.Error.Type.PAYMENT_PROCESSING,
data_ = "keep-alive"
data_ = InAppPaymentKeepAliveJob.KEEP_ALIVE
)
)
)