Single threaded sync executor with error reporting

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

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

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

Loading…
Cancel
Save