Cleanup after operation errors

pull/174/head
M66B 5 years ago
parent ce6b0b126b
commit b7acf7a288

@ -152,6 +152,7 @@ class Core {
" folder=" + op.folder + " folder=" + op.folder +
" msg=" + op.message + " msg=" + op.message +
" args=" + op.args + " args=" + op.args +
" group=" + group +
" retry=" + retry); " retry=" + retry);
// Fetch most recent copy of message // Fetch most recent copy of message
@ -242,14 +243,9 @@ class Core {
db.beginTransaction(); db.beginTransaction();
db.operation().setOperationError(op.id, null); db.operation().setOperationError(op.id, null);
for (TupleOperationEx s : similar.keySet())
db.operation().setOperationError(s.id, null);
if (message != null) { if (message != null)
db.message().setMessageError(message.id, null); db.message().setMessageError(message.id, null);
for (EntityMessage m : similar.values())
db.message().setMessageError(m.id, null);
}
if (!EntityOperation.SYNC.equals(op.name)) { if (!EntityOperation.SYNC.equals(op.name)) {
db.operation().setOperationState(op.id, "executing"); db.operation().setOperationState(op.id, "executing");
@ -391,33 +387,27 @@ class Core {
state.error(ex); state.error(ex);
if (similar.size() > 0) {
// Retry individually
group = false;
// Finally will reset state
continue;
}
try { try {
db.beginTransaction(); db.beginTransaction();
db.operation().setOperationError(op.id, Log.formatThrowable(ex)); op.error = Log.formatThrowable(ex);
for (TupleOperationEx s : similar.keySet()) db.operation().setOperationError(op.id, op.error);
db.operation().setOperationError(s.id, Log.formatThrowable(ex));
if (message != null && !(ex instanceof IllegalArgumentException)) { if (message != null && !(ex instanceof IllegalArgumentException))
db.message().setMessageError(message.id, Log.formatThrowable(ex)); db.message().setMessageError(message.id, Log.formatThrowable(ex));
for (EntityMessage m : similar.values())
db.message().setMessageError(m.id, Log.formatThrowable(ex));
}
if (similar.size() > 0 && !(ex instanceof IllegalArgumentException))
db.folder().setFolderError(folder.id, Log.formatThrowable(ex));
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
db.endTransaction(); db.endTransaction();
} }
if (similar.size() > 0) {
// Retry individually
group = false;
continue;
}
if (ex instanceof OutOfMemoryError || if (ex instanceof OutOfMemoryError ||
ex instanceof MessageRemovedException || ex instanceof MessageRemovedException ||
ex instanceof MessageRemovedIOException || ex instanceof MessageRemovedIOException ||
@ -443,13 +433,12 @@ class Core {
try { try {
db.beginTransaction(); db.beginTransaction();
// Cleanup operation
op.cleanup(context);
// There is no use in repeating // There is no use in repeating
db.operation().deleteOperation(op.id); db.operation().deleteOperation(op.id);
// Cleanup folder
if (EntityOperation.SYNC.equals(op.name))
db.folder().setFolderSyncState(folder.id, null);
// Cleanup messages // Cleanup messages
if (message != null && if (message != null &&
(ex instanceof MessageRemovedException || (ex instanceof MessageRemovedException ||
@ -458,9 +447,6 @@ class Core {
ex.getCause() instanceof MessageRemovedIOException)) ex.getCause() instanceof MessageRemovedIOException))
db.message().deleteMessage(message.id); db.message().deleteMessage(message.id);
// Cleanup operations
op.cleanup(context);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
db.endTransaction(); db.endTransaction();
@ -477,6 +463,7 @@ class Core {
} }
} }
} finally { } finally {
// Reset operation state
try { try {
db.beginTransaction(); db.beginTransaction();
@ -494,11 +481,19 @@ class Core {
} }
} }
for (TupleOperationEx op : ops) if (state.isRunning() && state.isRecoverable())
op.cleanup(context); try {
db.beginTransaction();
for (TupleOperationEx op : ops) {
Log.e("Operation=" + op.name + " error=" + op.error);
op.cleanup(context);
db.operation().deleteOperation(op.id);
}
if (ops.size() > 0 && state.isRunning() && state.isRecoverable()) db.setTransactionSuccessful();
Log.e("Operations failed=" + ops.size()); } finally {
db.endTransaction();
}
} finally { } finally {
Log.i(folder.name + " end process state=" + state); Log.i(folder.name + " end process state=" + state);

@ -440,6 +440,9 @@ public class EntityOperation {
Log.e(ex); Log.e(ex);
} }
if (EntityOperation.SYNC.equals(name))
db.folder().setFolderSyncState(folder, null);
if (message != null) { if (message != null) {
EntityMessage m = db.message().getMessage(message); EntityMessage m = db.message().getMessage(message);
if (m == null || m.uid == null) if (m == null || m.uid == null)

Loading…
Cancel
Save