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 {