mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 09:17:44 +00:00
37 lines
972 B
Java
37 lines
972 B
Java
|
package org.thoughtcrime.securesms.jobs;
|
||
|
|
||
|
import android.support.annotation.NonNull;
|
||
|
|
||
|
import org.thoughtcrime.securesms.jobmanager.Job;
|
||
|
import org.thoughtcrime.securesms.jobmanager.JobLogger;
|
||
|
import org.thoughtcrime.securesms.logging.Log;
|
||
|
|
||
|
public abstract class BaseJob extends Job {
|
||
|
|
||
|
private static final String TAG = BaseJob.class.getSimpleName();
|
||
|
|
||
|
public BaseJob(@NonNull Parameters parameters) {
|
||
|
super(parameters);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public @NonNull Result run() {
|
||
|
try {
|
||
|
onRun();
|
||
|
return Result.SUCCESS;
|
||
|
} catch (Exception e) {
|
||
|
if (onShouldRetry(e)) {
|
||
|
Log.i(TAG, JobLogger.format(this, "Encountered a retryable exception."), e);
|
||
|
return Result.RETRY;
|
||
|
} else {
|
||
|
Log.w(TAG, JobLogger.format(this, "Encountered a failing exception."), e);
|
||
|
return Result.FAILURE;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
protected abstract void onRun() throws Exception;
|
||
|
|
||
|
protected abstract boolean onShouldRetry(@NonNull Exception e);
|
||
|
}
|