Fix sepa badge redemption job.

This commit is contained in:
Cody Henthorne
2023-12-04 13:51:53 -05:00
parent 19e726a630
commit 3ca4e33d94
20 changed files with 132 additions and 128 deletions

View File

@@ -43,7 +43,7 @@ public class JobManager implements ConstraintObserver.Notifier {
private static final String TAG = Log.tag(JobManager.class);
public static final int CURRENT_VERSION = 10;
public static final int CURRENT_VERSION = 11;
private final Application application;
private final Configuration configuration;

View File

@@ -1,66 +0,0 @@
package org.thoughtcrime.securesms.jobmanager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/**
* Create a subclass of this to perform a migration on persisted {@link Job}s. A migration targets
* a specific end version, and the assumption is that it can migrate jobs to that end version from
* the previous version. The class will be provided a bundle of job data for each persisted job and
* give back an updated version (if applicable).
*/
public abstract class JobMigration {
private final int endVersion;
protected JobMigration(int endVersion) {
this.endVersion = endVersion;
}
/**
* Given a bundle of job data, return a bundle of job data that should be used in place of it.
* You may obviously return the same object if you don't wish to change it.
*/
protected abstract @NonNull JobData migrate(@NonNull JobData jobData);
int getEndVersion() {
return endVersion;
}
public static class JobData {
private final String factoryKey;
private final String queueKey;
private final byte[] data;
public JobData(@NonNull String factoryKey, @Nullable String queueKey, @Nullable byte[] data) {
this.factoryKey = factoryKey;
this.queueKey = queueKey;
this.data = data;
}
public @NonNull JobData withFactoryKey(@NonNull String newFactoryKey) {
return new JobData(newFactoryKey, queueKey, data);
}
public @NonNull JobData withQueueKey(@Nullable String newQueueKey) {
return new JobData(factoryKey, newQueueKey, data);
}
public @NonNull JobData withData(@Nullable byte[] newData) {
return new JobData(factoryKey, queueKey, newData);
}
public @NonNull String getFactoryKey() {
return factoryKey;
}
public @Nullable String getQueueKey() {
return queueKey;
}
public @NonNull byte[] getData() {
return data;
}
}
}

View File

@@ -0,0 +1,41 @@
package org.thoughtcrime.securesms.jobmanager
/**
* Create a subclass of this to perform a migration on persisted [Job]s. A migration targets
* a specific end version, and the assumption is that it can migrate jobs to that end version from
* the previous version. The class will be provided a bundle of job data for each persisted job and
* give back an updated version (if applicable).
*/
abstract class JobMigration protected constructor(val endVersion: Int) {
/**
* Given a bundle of job data, return a bundle of job data that should be used in place of it.
* You may obviously return the same object if you don't wish to change it.
*/
abstract fun migrate(jobData: JobData): JobData
data class JobData(
val factoryKey: String,
val queueKey: String?,
val maxAttempts: Int,
val lifespan: Long,
val data: ByteArray?
) {
fun withFactoryKey(newFactoryKey: String): JobData {
return copy(factoryKey = newFactoryKey)
}
fun withQueueKey(newQueueKey: String?): JobData {
return copy(queueKey = newQueueKey)
}
fun withData(newData: ByteArray?): JobData {
return copy(data = newData)
}
companion object {
@JvmField
val FAILING_JOB_DATA = JobData("FailingJob", null, -1, -1, null)
}
}
}

View File

@@ -59,7 +59,7 @@ public class JobMigrator {
while (iter.hasNext()) {
JobSpec jobSpec = iter.next();
JobData originalJobData = new JobData(jobSpec.getFactoryKey(), jobSpec.getQueueKey(), jobSpec.getSerializedData());
JobData originalJobData = new JobData(jobSpec.getFactoryKey(), jobSpec.getQueueKey(), jobSpec.getMaxAttempts(), jobSpec.getLifespan(), jobSpec.getSerializedData());
JobData updatedJobData = migration.migrate(originalJobData);
JobSpec updatedJobSpec = new JobSpec(jobSpec.getId(),
updatedJobData.getFactoryKey(),
@@ -68,8 +68,8 @@ public class JobMigrator {
jobSpec.getLastRunAttemptTime(),
jobSpec.getNextBackoffInterval(),
jobSpec.getRunAttempt(),
jobSpec.getMaxAttempts(),
jobSpec.getLifespan(),
updatedJobData.getMaxAttempts(),
updatedJobData.getLifespan(),
updatedJobData.getData(),
jobSpec.getSerializedInputData(),
jobSpec.isRunning(),

View File

@@ -0,0 +1,19 @@
package org.thoughtcrime.securesms.jobmanager.migrations
import org.thoughtcrime.securesms.jobmanager.JobMigration
/**
* Migrate DonationReceiptRedemptionJob to use more lax lifespan and retries to accommodate SEPA.
*/
class DonationReceiptRedemptionJobMigration : JobMigration(11) {
override fun migrate(jobData: JobData): JobData {
return if ("DonationReceiptRedemptionJob" == jobData.factoryKey) {
jobData.copy(
maxAttempts = 1500,
lifespan = -1
)
} else {
jobData
}
}
}

View File

@@ -18,7 +18,7 @@ public class PushDecryptMessageJobEnvelopeMigration extends JobMigration {
}
@Override
protected @NonNull JobData migrate(@NonNull JobData jobData) {
public @NonNull JobData migrate(@NonNull JobData jobData) {
return jobData;
}
}

View File

@@ -36,7 +36,7 @@ public class PushProcessMessageQueueJobMigration extends JobMigration {
}
@Override
protected @NonNull JobData migrate(@NonNull JobData jobData) {
public @NonNull JobData migrate(@NonNull JobData jobData) {
if ("PushProcessJob".equals(jobData.getFactoryKey())) {
Log.i(TAG, "Found a PushProcessMessageJob to migrate.");
try {

View File

@@ -21,7 +21,7 @@ public class RecipientIdFollowUpJobMigration extends JobMigration {
}
@Override
protected @NonNull JobData migrate(@NonNull JobData jobData) {
public @NonNull JobData migrate(@NonNull JobData jobData) {
switch(jobData.getFactoryKey()) {
case "RequestGroupInfoJob": return migrateRequestGroupInfoJob(jobData);
case "SendDeliveryReceiptJob": return migrateSendDeliveryReceiptJob(jobData);
@@ -54,6 +54,6 @@ public class RecipientIdFollowUpJobMigration extends JobMigration {
}
private static JobData failingJobData() {
return new JobData("FailingJob", null, null);
return JobData.FAILING_JOB_DATA;
}
}

View File

@@ -26,7 +26,7 @@ public class RecipientIdJobMigration extends JobMigration {
}
@Override
protected @NonNull JobData migrate(@NonNull JobData jobData) {
public @NonNull JobData migrate(@NonNull JobData jobData) {
switch(jobData.getFactoryKey()) {
case "MultiDeviceContactUpdateJob": return migrateMultiDeviceContactUpdateJob(jobData);
case "MultiDeviceRevealUpdateJob": return migrateMultiDeviceViewOnceOpenJob(jobData);

View File

@@ -15,7 +15,7 @@ public class RetrieveProfileJobMigration extends JobMigration {
}
@Override
protected @NonNull JobData migrate(@NonNull JobData jobData) {
public @NonNull JobData migrate(@NonNull JobData jobData) {
Log.i(TAG, "Running.");
if ("RetrieveProfileJob".equals(jobData.getFactoryKey())) {

View File

@@ -19,7 +19,7 @@ public class SendReadReceiptsJobMigration extends JobMigration {
}
@Override
protected @NonNull JobData migrate(@NonNull JobData jobData) {
public @NonNull JobData migrate(@NonNull JobData jobData) {
if ("SendReadReceiptJob".equals(jobData.getFactoryKey())) {
return migrateSendReadReceiptJob(messageTable, jobData);
}
@@ -41,7 +41,7 @@ public class SendReadReceiptsJobMigration extends JobMigration {
}
if (threadIds.size() != 1) {
return new JobData("FailingJob", null, null);
return JobData.FAILING_JOB_DATA;
} else {
return jobData.withData(data.buildUpon().putLong("thread", threadIds.first()).serialize());
}

View File

@@ -35,7 +35,7 @@ public class SenderKeyDistributionSendJobRecipientMigration extends JobMigration
}
@Override
protected @NonNull JobData migrate(@NonNull JobData jobData) {
public @NonNull JobData migrate(@NonNull JobData jobData) {
if ("SenderKeyDistributionSendJob".equals(jobData.getFactoryKey())) {
return migrateJob(jobData, groupDatabase);
} else {

View File

@@ -28,17 +28,15 @@ import org.whispersystems.signalservice.internal.ServiceResponse;
import java.io.IOException;
import java.util.Collections;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import okio.ByteString;
/**
* Job to redeem a verified donation receipt. It is up to the Job prior in the chain to specify a valid
* presentation object via setOutputData. This is expected to be the byte[] blob of a ReceiptCredentialPresentation object.
*/
public class DonationReceiptRedemptionJob extends BaseJob {
private static final String TAG = Log.tag(DonationReceiptRedemptionJob.class);
private static final long NO_ID = -1L;
private static final String TAG = Log.tag(DonationReceiptRedemptionJob.class);
private static final long NO_ID = -1L;
private static final int MAX_RETRIES = 1500;
public static final String SUBSCRIPTION_QUEUE = "ReceiptRedemption";
public static final String ONE_TIME_QUEUE = "BoostReceiptRedemption";
@@ -71,8 +69,8 @@ public class DonationReceiptRedemptionJob extends BaseJob {
.Builder()
.addConstraint(NetworkConstraint.KEY)
.setQueue(SUBSCRIPTION_QUEUE + (isLongRunningDonationPaymentType ? LONG_RUNNING_QUEUE_SUFFIX : ""))
.setMaxAttempts(Parameters.UNLIMITED)
.setLifespan(TimeUnit.DAYS.toMillis(1))
.setMaxAttempts(MAX_RETRIES)
.setLifespan(Parameters.IMMORTAL)
.build());
}
@@ -86,8 +84,8 @@ public class DonationReceiptRedemptionJob extends BaseJob {
.Builder()
.addConstraint(NetworkConstraint.KEY)
.setQueue(ONE_TIME_QUEUE + (isLongRunningDonationPaymentType ? LONG_RUNNING_QUEUE_SUFFIX : ""))
.setMaxAttempts(Parameters.UNLIMITED)
.setLifespan(TimeUnit.DAYS.toMillis(1))
.setMaxAttempts(MAX_RETRIES)
.setLifespan(Parameters.IMMORTAL)
.build());
}
@@ -112,8 +110,8 @@ public class DonationReceiptRedemptionJob extends BaseJob {
.Builder()
.addConstraint(NetworkConstraint.KEY)
.setQueue("GiftReceiptRedemption-" + messageId)
.setMaxAttempts(Parameters.UNLIMITED)
.setLifespan(TimeUnit.DAYS.toMillis(1))
.setMaxAttempts(MAX_RETRIES)
.setLifespan(Parameters.IMMORTAL)
.build());
RefreshOwnProfileJob refreshOwnProfileJob = new RefreshOwnProfileJob();

View File

@@ -26,6 +26,7 @@ import org.thoughtcrime.securesms.jobmanager.impl.NotInCallConstraint;
import org.thoughtcrime.securesms.jobmanager.impl.NotInCallConstraintObserver;
import org.thoughtcrime.securesms.jobmanager.impl.SqlCipherMigrationConstraint;
import org.thoughtcrime.securesms.jobmanager.impl.SqlCipherMigrationConstraintObserver;
import org.thoughtcrime.securesms.jobmanager.migrations.DonationReceiptRedemptionJobMigration;
import org.thoughtcrime.securesms.jobmanager.migrations.PushDecryptMessageJobEnvelopeMigration;
import org.thoughtcrime.securesms.jobmanager.migrations.PushProcessMessageJobMigration;
import org.thoughtcrime.securesms.jobmanager.migrations.PushProcessMessageQueueJobMigration;
@@ -343,6 +344,7 @@ public final class JobManagerFactories {
new RetrieveProfileJobMigration(),
new PushDecryptMessageJobEnvelopeMigration(),
new SenderKeyDistributionSendJobRecipientMigration(),
new PushProcessMessageJobMigration());
new PushProcessMessageJobMigration(),
new DonationReceiptRedemptionJobMigration());
}
}

View File

@@ -112,8 +112,8 @@ public final class FeatureFlags {
public static final String USERNAMES = "android.usernames";
public static final String INSTANT_VIDEO_PLAYBACK = "android.instantVideoPlayback";
public static final String CRASH_PROMPT_CONFIG = "android.crashPromptConfig";
private static final String SEPA_DEBIT_DONATIONS = "android.sepa.debit.donations.4";
private static final String IDEAL_DONATIONS = "android.ideal.donations.4";
private static final String SEPA_DEBIT_DONATIONS = "android.sepa.debit.donations.5";
private static final String IDEAL_DONATIONS = "android.ideal.donations.5";
public static final String IDEAL_ENABLED_REGIONS = "global.donations.idealEnabledRegions";
public static final String SEPA_ENABLED_REGIONS = "global.donations.sepaEnabledRegions";