Skip to content

Commit

Permalink
Fix retry issues with RotateProfileKeyJob.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Jul 19, 2020
1 parent 5468f17 commit 6a9476c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
import org.whispersystems.signalservice.api.util.StreamDetails;

import java.util.concurrent.TimeUnit;

public final class ProfileUploadJob extends BaseJob {

private static final String TAG = Log.tag(ProfileUploadJob.class);
Expand All @@ -34,9 +36,9 @@ public ProfileUploadJob() {
this(new Job.Parameters.Builder()
.addConstraint(NetworkConstraint.KEY)
.setQueue(QUEUE)
.setLifespan(Parameters.IMMORTAL)
.setLifespan(TimeUnit.DAYS.toMillis(30))
.setMaxAttempts(Parameters.UNLIMITED)
.setMaxInstances(1)
.setMaxInstances(2)
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public RefreshAttributesJob() {
this(new Job.Parameters.Builder()
.addConstraint(NetworkConstraint.KEY)
.setQueue("RefreshAttributesJob")
.setMaxInstances(2)
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public class RotateProfileKeyJob extends BaseJob {
public RotateProfileKeyJob() {
this(new Job.Parameters.Builder()
.setQueue("__ROTATE_PROFILE_KEY__")
.addConstraint(NetworkConstraint.KEY)
.setMaxAttempts(25)
.setMaxInstances(1)
.setMaxInstances(2)
.build());
}

Expand All @@ -47,21 +45,13 @@ private RotateProfileKeyJob(@NonNull Job.Parameters parameters) {
}

@Override
public void onRun() throws Exception {
SignalServiceAccountManager accountManager = ApplicationDependencies.getSignalServiceAccountManager();
RecipientDatabase recipientDatabase = DatabaseFactory.getRecipientDatabase(context);
ProfileKey profileKey = ProfileKeyUtil.createNew();
Recipient self = Recipient.self();
public void onRun() {
ProfileKey newProfileKey = ProfileKeyUtil.createNew();
Recipient self = Recipient.self();

recipientDatabase.setProfileKey(self.getId(), profileKey);

try (StreamDetails avatarStream = AvatarHelper.getSelfProfileAvatarStream(context)) {
accountManager.setVersionedProfile(self.getUuid().get(),
profileKey,
Recipient.self().getProfileName().serialize(),
avatarStream);
}
DatabaseFactory.getRecipientDatabase(context).setProfileKey(self.getId(), newProfileKey);

ApplicationDependencies.getJobManager().add(new ProfileUploadJob());
ApplicationDependencies.getJobManager().add(new RefreshAttributesJob());

updateProfileKeyOnAllV2Groups();
Expand All @@ -77,12 +67,11 @@ private void updateProfileKeyOnAllV2Groups() {

@Override
public void onFailure() {

}

@Override
protected boolean onShouldRetry(@NonNull Exception exception) {
return exception instanceof PushNetworkException;
return false;
}

public static final class Factory implements Job.Factory<RotateProfileKeyJob> {
Expand Down

0 comments on commit 6a9476c

Please sign in to comment.