That fuck shit the fascists are using
1package org.tm.archive.migrations;
2
3import androidx.annotation.NonNull;
4import androidx.annotation.Nullable;
5
6import org.greenrobot.eventbus.EventBus;
7import org.tm.archive.jobmanager.JsonJobData;
8import org.tm.archive.jobmanager.Job;
9import org.tm.archive.jobs.BaseJob;
10
11/**
12 * A job that should be enqueued last in a series of migrations. When this runs, we know that the
13 * current set of migrations has been completed.
14 *
15 * To avoid confusion around the possibility of multiples of these jobs being enqueued as the
16 * result of doing multiple migrations, we associate the canonicalVersionCode with the job and
17 * include that in the event we broadcast out.
18 */
19public class MigrationCompleteJob extends BaseJob {
20
21 public static final String KEY = "MigrationCompleteJob";
22
23 private final static String KEY_VERSION = "version";
24
25 private final int version;
26
27 MigrationCompleteJob(int version) {
28 this(new Parameters.Builder()
29 .setQueue(Parameters.MIGRATION_QUEUE_KEY)
30 .setLifespan(Parameters.IMMORTAL)
31 .setMaxAttempts(Parameters.UNLIMITED)
32 .build(),
33 version);
34 }
35
36 private MigrationCompleteJob(@NonNull Job.Parameters parameters, int version) {
37 super(parameters);
38 this.version = version;
39 }
40
41 @Override
42 public @Nullable byte[] serialize() {
43 return new JsonJobData.Builder().putInt(KEY_VERSION, version).serialize();
44 }
45
46 @Override
47 public @NonNull String getFactoryKey() {
48 return KEY;
49 }
50
51 @Override
52 public void onFailure() {
53 throw new AssertionError("This job should never fail.");
54 }
55
56 @Override
57 protected void onRun() throws Exception {
58 EventBus.getDefault().postSticky(new MigrationCompleteEvent(version));
59 }
60
61 @Override
62 protected boolean onShouldRetry(@NonNull Exception e) {
63 return true;
64 }
65
66 public static class Factory implements Job.Factory<MigrationCompleteJob> {
67 @Override
68 public @NonNull MigrationCompleteJob create(@NonNull Parameters parameters, @Nullable byte[] serializedData) {
69 JsonJobData data = JsonJobData.deserialize(serializedData);
70 return new MigrationCompleteJob(parameters, data.getInt(KEY_VERSION));
71 }
72 }
73}