Sync error reporting

pull/14/head
Sam Bosley 13 years ago
parent c4b0a3629c
commit f6ff8d0e60

@ -1,7 +1,46 @@
package com.todoroo.astrid.sync; package com.todoroo.astrid.sync;
import java.io.IOException;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService;
abstract public class SyncV2Provider { abstract public class SyncV2Provider {
public class SyncExceptionHandler {
public void handleException(String tag, Exception e) {
//TODO: When Crittercism supports it, report error to them
getUtilities().setLastError(e.toString());
// occurs when application was closed
if(e instanceof IllegalStateException) {
exceptionService.reportError(tag + "-caught", e); //$NON-NLS-1$
}
// occurs when network error
else if(e instanceof IOException) {
exceptionService.reportError(tag + "-io", e); //$NON-NLS-1$
}
// unhandled error
else {
exceptionService.reportError(tag + "-unhandled", e); //$NON-NLS-1$
}
}
}
@Autowired
protected ExceptionService exceptionService;
protected final SyncExceptionHandler handler;
public SyncV2Provider() {
DependencyInjectionService.getInstance().inject(this);
handler = new SyncExceptionHandler();
}
/** /**
* @return sync provider name (displayed in sync menu) * @return sync provider name (displayed in sync menu)
*/ */
@ -32,6 +71,11 @@ abstract public class SyncV2Provider {
*/ */
abstract public void signOut(); abstract public void signOut();
/**
* @return sync utility instance
*/
abstract protected SyncProviderUtilities getUtilities();
@Override @Override
public String toString() { public String toString() {
return getName(); return getName();

@ -59,6 +59,7 @@ import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.service.TagDataService; import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.sync.SyncV2Provider.SyncExceptionHandler;
import com.todoroo.astrid.tags.TagService; import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.utility.Flags; import com.todoroo.astrid.utility.Flags;
@ -583,7 +584,7 @@ public final class ActFmSyncService {
* Fetch tagData listing asynchronously * Fetch tagData listing asynchronously
*/ */
public void fetchTagDataDashboard(boolean manual, final Runnable done) { public void fetchTagDataDashboard(boolean manual, final Runnable done) {
invokeFetchList("goal", manual, new ListItemProcessor<TagData>() { invokeFetchList("goal", manual, null, new ListItemProcessor<TagData>() {
@Override @Override
protected void mergeAndSave(JSONArray list, HashMap<Long,Long> locals) throws JSONException { protected void mergeAndSave(JSONArray list, HashMap<Long,Long> locals) throws JSONException {
TagData remote = new TagData(); TagData remote = new TagData();
@ -686,8 +687,8 @@ public final class ActFmSyncService {
* @param manual * @param manual
* @param done * @param done
*/ */
public void fetchActiveTasks(final boolean manual, Runnable done) { public void fetchActiveTasks(final boolean manual, SyncExceptionHandler handler, Runnable done) {
invokeFetchList("task", manual, new ListItemProcessor<Task>() { invokeFetchList("task", manual, handler, new ListItemProcessor<Task>() {
@Override @Override
protected void mergeAndSave(JSONArray list, HashMap<Long,Long> locals) throws JSONException { protected void mergeAndSave(JSONArray list, HashMap<Long,Long> locals) throws JSONException {
Task remote = new Task(); Task remote = new Task();
@ -733,7 +734,7 @@ public final class ActFmSyncService {
* @param done * @param done
*/ */
public void fetchTasksForTag(final TagData tagData, final boolean manual, Runnable done) { public void fetchTasksForTag(final TagData tagData, final boolean manual, Runnable done) {
invokeFetchList("task", manual, new ListItemProcessor<Task>() { invokeFetchList("task", manual, null, new ListItemProcessor<Task>() {
@Override @Override
protected void mergeAndSave(JSONArray list, HashMap<Long,Long> locals) throws JSONException { protected void mergeAndSave(JSONArray list, HashMap<Long,Long> locals) throws JSONException {
Task remote = new Task(); Task remote = new Task();
@ -782,7 +783,7 @@ public final class ActFmSyncService {
* @param done * @param done
*/ */
public void fetchUpdatesForTag(final TagData tagData, final boolean manual, Runnable done) { public void fetchUpdatesForTag(final TagData tagData, final boolean manual, Runnable done) {
invokeFetchList("activity", manual, new UpdateListItemProcessor(), done, invokeFetchList("activity", manual, null, new UpdateListItemProcessor(), done,
"updates:" + tagData.getId(), "tag_id", tagData.getValue(TagData.REMOTE_ID)); "updates:" + tagData.getId(), "tag_id", tagData.getValue(TagData.REMOTE_ID));
} }
@ -793,7 +794,7 @@ public final class ActFmSyncService {
* @param runnable * @param runnable
*/ */
public void fetchUpdatesForTask(final Task task, boolean manual, Runnable done) { public void fetchUpdatesForTask(final Task task, boolean manual, Runnable done) {
invokeFetchList("activity", manual, new UpdateListItemProcessor(), done, invokeFetchList("activity", manual, null, new UpdateListItemProcessor(), done,
"comments:" + task.getId(), "task_id", task.getValue(Task.REMOTE_ID)); "comments:" + task.getId(), "task_id", task.getValue(Task.REMOTE_ID));
} }
@ -803,7 +804,7 @@ public final class ActFmSyncService {
* @param done * @param done
*/ */
public void fetchPersonalUpdates(boolean manual, Runnable done) { public void fetchPersonalUpdates(boolean manual, Runnable done) {
invokeFetchList("activity", manual, new UpdateListItemProcessor(), done, "personal"); invokeFetchList("activity", manual, null, new UpdateListItemProcessor(), done, "personal");
} }
private class UpdateListItemProcessor extends ListItemProcessor<Update> { private class UpdateListItemProcessor extends ListItemProcessor<Update> {
@ -931,7 +932,7 @@ public final class ActFmSyncService {
} }
/** Call sync method */ /** Call sync method */
private void invokeFetchList(final String model, final boolean manual, private void invokeFetchList(final String model, final boolean manual, final SyncExceptionHandler handler,
final ListItemProcessor<?> processor, final Runnable done, final String lastSyncKey, final ListItemProcessor<?> processor, final Runnable done, final String lastSyncKey,
Object... params) { Object... params) {
if(!checkForToken()) if(!checkForToken())
@ -955,7 +956,10 @@ public final class ActFmSyncService {
if(done != null) if(done != null)
done.run(); done.run();
} catch (IOException e) { } catch (IOException e) {
handleException("io-exception-list-" + model, e); if (handler != null)
handler.handleException("io-exception-list-" + model, e);
else
handleException("io-exception-list-" + model, e);
} catch (JSONException e) { } catch (JSONException e) {
handleException("json: " + result.toString(), e); handleException("json: " + result.toString(), e);
} }

@ -13,8 +13,6 @@ import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.utility.Preferences;
@ -38,23 +36,22 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
@Autowired ActFmSyncService actFmSyncService; @Autowired ActFmSyncService actFmSyncService;
@Autowired ExceptionService exceptionService;
@Autowired TaskService taskService; @Autowired TaskService taskService;
static { static {
AstridDependencyInjector.initialize(); AstridDependencyInjector.initialize();
} }
public ActFmSyncV2Provider() {
DependencyInjectionService.getInstance().inject(this);
}
@Override @Override
public String getName() { public String getName() {
return ContextManager.getString(R.string.actfm_APr_header); return ContextManager.getString(R.string.actfm_APr_header);
} }
@Override
public ActFmPreferenceService getUtilities() {
return actFmPreferenceService;
}
@Override @Override
public void signOut() { public void signOut() {
actFmPreferenceService.setToken(null); actFmPreferenceService.setToken(null);
@ -98,9 +95,9 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
time = actFmSyncService.fetchTags(time); time = actFmSyncService.fetchTags(time);
Preferences.setInt(LAST_TAG_FETCH_TIME, time); Preferences.setInt(LAST_TAG_FETCH_TIME, time);
} catch (JSONException e) { } catch (JSONException e) {
exceptionService.reportError("actfm-sync", e); //$NON-NLS-1$ handler.handleException("actfm-sync", e); //$NON-NLS-1$
} catch (IOException e) { } catch (IOException e) {
exceptionService.reportError("actfm-sync", e); //$NON-NLS-1$ handler.handleException("actfm-sync", e); //$NON-NLS-1$
} finally { } finally {
callback.incrementProgress(20); callback.incrementProgress(20);
if(finisher.decrementAndGet() == 0) { if(finisher.decrementAndGet() == 0) {
@ -115,7 +112,7 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
/** @return runnable to fetch changes to tags */ /** @return runnable to fetch changes to tags */
private void startTaskFetcher(final boolean manual, final SyncResultCallback callback, private void startTaskFetcher(final boolean manual, final SyncResultCallback callback,
final AtomicInteger finisher) { final AtomicInteger finisher) {
actFmSyncService.fetchActiveTasks(manual, new Runnable() { actFmSyncService.fetchActiveTasks(manual, handler, new Runnable() {
@Override @Override
public void run() { public void run() {
pushQueued(callback, finisher); pushQueued(callback, finisher);

@ -16,7 +16,6 @@ import com.todoroo.andlib.data.AbstractModel;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Join; import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
@ -61,15 +60,16 @@ public class GtasksSyncV2Provider extends SyncV2Provider {
AstridDependencyInjector.initialize(); AstridDependencyInjector.initialize();
} }
public GtasksSyncV2Provider() {
DependencyInjectionService.getInstance().inject(this);
}
@Override @Override
public String getName() { public String getName() {
return ContextManager.getString(R.string.gtasks_GPr_header); return ContextManager.getString(R.string.gtasks_GPr_header);
} }
@Override
public GtasksPreferenceService getUtilities() {
return gtasksPreferenceService;
}
@Override @Override
public void signOut() { public void signOut() {
gtasksPreferenceService.clearLastSyncDate(); gtasksPreferenceService.clearLastSyncDate();
@ -97,7 +97,7 @@ public class GtasksSyncV2Provider extends SyncV2Provider {
try { try {
gtasksListService.updateLists(invoker.allGtaskLists()); gtasksListService.updateLists(invoker.allGtaskLists());
} catch (IOException e) { } catch (IOException e) {
// error updating lists handler.handleException("gtasks-sync=io", e); //$NON-NLS-1$
} finally { } finally {
callback.incrementMax(25); callback.incrementMax(25);
} }
@ -110,7 +110,7 @@ public class GtasksSyncV2Provider extends SyncV2Provider {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
synchronizeListHelper(list, invoker, callback); synchronizeListHelper(list, invoker, handler, callback);
if (finisher.decrementAndGet() == 0) { if (finisher.decrementAndGet() == 0) {
gtasksPreferenceService.recordSuccessfulSync(); gtasksPreferenceService.recordSuccessfulSync();
callback.finished(); callback.finished();
@ -136,7 +136,7 @@ public class GtasksSyncV2Provider extends SyncV2Provider {
try { try {
gtasksSyncService.pushTaskOnSave(task, task.getMergedValues(), invoker, false); gtasksSyncService.pushTaskOnSave(task, task.getMergedValues(), invoker, false);
} catch (IOException e) { } catch (IOException e) {
// Eh handler.handleException("gtasks-sync-io", e); //$NON-NLS-1$
} finally { } finally {
callback.incrementProgress(10); callback.incrementProgress(10);
} }
@ -166,7 +166,7 @@ public class GtasksSyncV2Provider extends SyncV2Provider {
String authToken = getValidatedAuthToken(); String authToken = getValidatedAuthToken();
callback.incrementProgress(25); callback.incrementProgress(25);
final GtasksInvoker service = new GtasksInvoker(authToken); final GtasksInvoker service = new GtasksInvoker(authToken);
synchronizeListHelper(gtasksList, service, callback); synchronizeListHelper(gtasksList, service, null, callback);
} finally { } finally {
callback.incrementProgress(25); callback.incrementProgress(25);
callback.finished(); callback.finished();
@ -188,7 +188,7 @@ public class GtasksSyncV2Provider extends SyncV2Provider {
} }
private void synchronizeListHelper(StoreObject list, GtasksInvoker invoker, SyncResultCallback callback) { private void synchronizeListHelper(StoreObject list, GtasksInvoker invoker, SyncExceptionHandler handler, SyncResultCallback callback) {
// Do stuff // Do stuff
String listId = list.getValue(GtasksList.REMOTE_ID); String listId = list.getValue(GtasksList.REMOTE_ID);
long lastSyncDate; long lastSyncDate;
@ -218,7 +218,8 @@ public class GtasksSyncV2Provider extends SyncV2Provider {
gtasksTaskListUpdater.correctOrderAndIndentForList(listId); gtasksTaskListUpdater.correctOrderAndIndentForList(listId);
} }
} catch (IOException e) { } catch (IOException e) {
// Stuff if (handler != null)
handler.handleException("gtasks-sync-io", e); //$NON-NLS-1$
} }
} }

Loading…
Cancel
Save