diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java index 6b28e371d..fe743af9d 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java @@ -8,6 +8,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; +import java.util.Queue; import org.apache.http.entity.mime.MultipartEntity; import org.apache.http.entity.mime.content.ByteArrayBody; @@ -86,7 +88,28 @@ public final class ActFmSyncService { DependencyInjectionService.getInstance().inject(this); } + private final Queue failedPushes = new LinkedList(); + public void initialize() { + new Thread(new Runnable() { + public void run() { + while (true) { + AndroidUtilities.sleepDeep(5000 * 60); // 5 minutes between tries + if(failedPushes.size() > 0) { + Queue toTry = new LinkedList(); // Copy into a second queue so we don't end up infinitely retrying in the same loop + while(failedPushes.size() > 0) { + toTry.add(failedPushes.remove()); + } + while(toTry.size() > 0) { + if (!actFmPreferenceService.isOngoing()) { + pushTask(toTry.remove()); + } + } + } + } + } + }).start(); + taskDao.addListener(new ModelUpdateListener() { @Override public void onModelUpdated(final Task model) { @@ -281,8 +304,12 @@ public final class ActFmSyncService { Flags.set(Flags.ACTFM_SUPPRESS_SYNC); taskDao.saveExisting(task); } catch (JSONException e) { + if (!failedPushes.contains(task.getId())) + failedPushes.add(task.getId()); handleException("task-save-json", e); } catch (IOException e) { + if (!failedPushes.contains(task.getId())) + failedPushes.add(task.getId()); handleException("task-save-io", e); } }