Single threaded sync executor with error reporting

pull/384/head 4.8.11
Alex Baker 8 years ago
parent a5871503e4
commit 1aec28a4e1

@ -27,7 +27,7 @@ android {
buildToolsVersion "23.0.2"
defaultConfig {
versionCode 400
versionCode 401
versionName "4.8.11"
minSdkVersion 14
targetSdkVersion 23

@ -1,7 +1,10 @@
package org.tasks.sync;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.todoroo.astrid.sync.SyncResultCallback;
import org.tasks.analytics.Tracker;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
@ -9,18 +12,21 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import timber.log.Timber;
import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static java.util.concurrent.ThreadPoolExecutor.DiscardPolicy;
public class SyncExecutor {
private final ExecutorService executor = new ThreadPoolExecutor(
0, Integer.MAX_VALUE,
60L, TimeUnit.SECONDS,
new SynchronousQueue<Runnable>(),
new DiscardPolicy());
private final ExecutorService executor = newSingleThreadExecutor(
new ThreadFactoryBuilder().setNameFormat("sync-executor-%d").build());
private final Tracker tracker;
@Inject
public SyncExecutor() {
public SyncExecutor(Tracker tracker) {
this.tracker = tracker;
}
public void execute(final SyncResultCallback callback, final Runnable command) {
@ -30,6 +36,8 @@ public class SyncExecutor {
try {
command.run();
} catch (Exception e) {
Timber.e(e, e.getMessage());
tracker.reportException(e);
executor.shutdownNow();
callback.finished();
}

Loading…
Cancel
Save