diff --git a/urbanairship-core/src/main/java/com/urbanairship/automation/AutomationEngine.java b/urbanairship-core/src/main/java/com/urbanairship/automation/AutomationEngine.java index 92bca646f..3354b254d 100644 --- a/urbanairship-core/src/main/java/com/urbanairship/automation/AutomationEngine.java +++ b/urbanairship-core/src/main/java/com/urbanairship/automation/AutomationEngine.java @@ -918,9 +918,17 @@ private void cleanSchedules() { } Set schedulesToDelete = new HashSet<>(); - for (ScheduleEntry entry : finished) { - if (System.currentTimeMillis() >= entry.getExecutionStateChangeDate() + entry.getEditGracePeriod()) { + long finishDate; + + // If grace period is unset - use the executionStateChangeDate as finishDate to avoid unnecessarily keeping schedules around + if (entry.getEditGracePeriod() == 0) { + finishDate = entry.getEnd() + entry.getEditGracePeriod(); + } else { + finishDate = entry.getExecutionStateChangeDate(); + } + + if (System.currentTimeMillis() >= finishDate) { schedulesToDelete.add(entry.scheduleId); } }