Cleanup after operation errors

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

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

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

Loading…
Cancel
Save