Limit send tries

This commit is contained in:
M66B 2020-06-11 19:28:47 +02:00
parent 40e19a242c
commit 985646746b
1 changed files with 17 additions and 5 deletions

View File

@ -75,6 +75,7 @@ public class ServiceSend extends ServiceBase {
private static final int PI_SEND = 1; private static final int PI_SEND = 1;
private static final long CONNECTIVITY_DELAY = 5000L; // milliseconds private static final long CONNECTIVITY_DELAY = 5000L; // milliseconds
private static final int IDENTITY_ERROR_AFTER = 30; // minutes private static final int IDENTITY_ERROR_AFTER = 30; // minutes
private static final int RETRY_MAX = 3;
@Override @Override
public void onCreate() { public void onCreate() {
@ -274,22 +275,31 @@ public class ServiceSend extends ServiceBase {
DB db = DB.getInstance(this); DB db = DB.getInstance(this);
EntityFolder outbox = db.folder().getOutbox(); EntityFolder outbox = db.folder().getOutbox();
try { try {
db.folder().setFolderError(outbox.id, null);
db.folder().setFolderSyncState(outbox.id, "syncing"); db.folder().setFolderSyncState(outbox.id, "syncing");
List<TupleOperationEx> ops = db.operation().getOperations(outbox.id); List<TupleOperationEx> ops = db.operation().getOperations(outbox.id);
Log.i(outbox.name + " pending operations=" + ops.size()); Log.i(outbox.name + " pending operations=" + ops.size());
if (ops.size() > 0) while (ops.size() > 0) {
db.folder().setFolderError(outbox.id, null); TupleOperationEx op = ops.get(0);
for (EntityOperation op : ops) {
EntityMessage message = null; EntityMessage message = null;
if (op.message != null)
message = db.message().getMessage(op.message);
try { try {
Log.i(outbox.name + Log.i(outbox.name +
" start op=" + op.id + "/" + op.name + " start op=" + op.id + "/" + op.name +
" msg=" + op.message + " msg=" + op.message +
" args=" + op.args); " args=" + op.args);
db.operation().setOperationTries(op.id, ++op.tries);
db.operation().setOperationError(op.id, null);
if (message != null)
db.message().setMessageError(message.id, null);
db.operation().setOperationState(op.id, "executing"); db.operation().setOperationState(op.id, "executing");
Map<String, String> crumb = new HashMap<>(); Map<String, String> crumb = new HashMap<>();
@ -307,7 +317,6 @@ public class ServiceSend extends ServiceBase {
break; break;
case EntityOperation.SEND: case EntityOperation.SEND:
message = db.message().getMessage(op.message);
if (message == null) if (message == null)
throw new MessageRemovedException(); throw new MessageRemovedException();
onSend(message); onSend(message);
@ -321,6 +330,7 @@ public class ServiceSend extends ServiceBase {
} }
db.operation().deleteOperation(op.id); db.operation().deleteOperation(op.id);
ops.remove(op);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(outbox.name, ex); Log.e(outbox.name, ex);
EntityLog.log(this, outbox.name + " " + Log.formatThrowable(ex, false)); EntityLog.log(this, outbox.name + " " + Log.formatThrowable(ex, false));
@ -329,7 +339,8 @@ public class ServiceSend extends ServiceBase {
if (message != null) if (message != null)
db.message().setMessageError(message.id, Log.formatThrowable(ex)); db.message().setMessageError(message.id, Log.formatThrowable(ex));
if (ex instanceof OutOfMemoryError || if (op.tries >= RETRY_MAX ||
ex instanceof OutOfMemoryError ||
ex instanceof MessageRemovedException || ex instanceof MessageRemovedException ||
ex instanceof FileNotFoundException || ex instanceof FileNotFoundException ||
ex instanceof AuthenticationFailedException || ex instanceof AuthenticationFailedException ||
@ -337,6 +348,7 @@ public class ServiceSend extends ServiceBase {
ex instanceof IllegalArgumentException) { ex instanceof IllegalArgumentException) {
Log.w("Unrecoverable"); Log.w("Unrecoverable");
db.operation().deleteOperation(op.id); db.operation().deleteOperation(op.id);
ops.remove(op);
continue; continue;
} else } else
throw ex; throw ex;