Skip to content

Commit b2e9bf7

Browse files
committed
Reorder and simplify statements to avoid confusion.
1 parent a6aa211 commit b2e9bf7

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

app/src/main/java/org/gnucash/android/service/ScheduledActionService.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,16 @@ private static void executeScheduledEvent(ScheduledAction scheduledAction, SQLit
143143
// one period has been skipped, all intermediate transactions can be created
144144

145145
scheduledAction.setLastRun(System.currentTimeMillis());
146+
//set the execution count in the object because it will be checked for the next iteration in the calling loop
147+
scheduledAction.setExecutionCount(executionCount); //this call is important, do not remove!!
146148
//update the last run time and execution count
147149
ContentValues contentValues = new ContentValues();
148-
contentValues.put(DatabaseSchema.ScheduledActionEntry.COLUMN_LAST_RUN, scheduledAction.getLastRunTime());
149-
contentValues.put(DatabaseSchema.ScheduledActionEntry.COLUMN_EXECUTION_COUNT, executionCount);
150+
contentValues.put(DatabaseSchema.ScheduledActionEntry.COLUMN_LAST_RUN,
151+
scheduledAction.getLastRunTime());
152+
contentValues.put(DatabaseSchema.ScheduledActionEntry.COLUMN_EXECUTION_COUNT,
153+
scheduledAction.getExecutionCount());
150154
db.update(DatabaseSchema.ScheduledActionEntry.TABLE_NAME, contentValues,
151155
DatabaseSchema.ScheduledActionEntry.COLUMN_UID + "=?", new String[]{scheduledAction.getUID()});
152-
153-
//set the execution count in the object because it will be checked for the next iteration in the calling loop
154-
scheduledAction.setExecutionCount(executionCount); //this call is important, do not remove!!
155156
}
156157

157158
/**
@@ -162,20 +163,18 @@ private static void executeScheduledEvent(ScheduledAction scheduledAction, SQLit
162163
* @return Number of times backup is executed. This should either be 1 or 0
163164
*/
164165
private static int executeBackup(ScheduledAction scheduledAction, SQLiteDatabase db) {
165-
int executionCount = 0;
166166
if (!shouldExecuteScheduledBackup(scheduledAction))
167167
return 0;
168168

169169
ExportParams params = ExportParams.parseCsv(scheduledAction.getTag());
170170
try {
171171
//wait for async task to finish before we proceed (we are holding a wake lock)
172172
new ExportAsyncTask(GnuCashApplication.getAppContext(), db).execute(params).get();
173-
scheduledAction.setExecutionCount(++executionCount);
174173
} catch (InterruptedException | ExecutionException e) {
175174
Crashlytics.logException(e);
176175
Log.e(LOG_TAG, e.getMessage());
177176
}
178-
return executionCount;
177+
return 1;
179178
}
180179

181180
private static boolean shouldExecuteScheduledBackup(ScheduledAction scheduledAction) {

0 commit comments

Comments
 (0)