mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(eventbridge): stop a scheduled rule's timer when its rule is gone (#5462)
* fix(eventbridge): stop a scheduled rule's timer when its rule is gone * fix(eventbridge): stop only the timer whose tick found its rule gone
This commit is contained in:
1 parent
2e4cfe7ac5
commit
d6f93abb18
2 files changed
+65
-6
No files matched your search
@@ -100,9 +100,9 @@ public class RuleScheduler implements Resettable {
|
||||
Supplier<ScheduleData> dataSupplier) {
|
||||
long intervalMs = ScheduleExpressionParser.parseRateToMillis(scheduleExpr);
|
||||
|
||||
tick(dataSupplier);
|
||||
long timerId = vertx.setPeriodic(intervalMs, id -> tick(dataSupplier));
|
||||
long timerId = vertx.setPeriodic(intervalMs, id -> tick(ruleArn, id, dataSupplier));
|
||||
scheduleContexts.put(ruleArn, new ScheduleContext(timerId, scheduleExpr));
|
||||
tick(ruleArn, timerId, dataSupplier);
|
||||
LOG.debugv("Started rate scheduler for rule {0} with interval {1}ms", ruleArn, intervalMs);
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public class RuleScheduler implements Resettable {
|
||||
}
|
||||
|
||||
long timerId = vertx.setTimer(delayMs, id -> {
|
||||
tick(dataSupplier);
|
||||
tick(ruleArn, id, dataSupplier);
|
||||
ScheduleContext current = scheduleContexts.get(ruleArn);
|
||||
if (current != null && current.timerId() == id) {
|
||||
scheduleCronFire(ruleArn, scheduleExpr, dataSupplier, current);
|
||||
@@ -150,12 +150,14 @@ public class RuleScheduler implements Resettable {
|
||||
}
|
||||
}
|
||||
|
||||
private void tick(Supplier<ScheduleData> dataSupplier) {
|
||||
private void tick(String ruleArn, long timerId, Supplier<ScheduleData> dataSupplier) {
|
||||
ScheduleData data = dataSupplier.get();
|
||||
|
||||
if (data == null || data.rule == null) {
|
||||
LOG.debugv("Rule no longer exists, stopping scheduler");
|
||||
stopScheduler(data != null && data.rule != null ? data.rule.getArn() : null);
|
||||
LOG.debugv("Rule {0} no longer exists, stopping its timer", ruleArn);
|
||||
vertx.cancelTimer(timerId);
|
||||
// A rule recreated under the same ARN may already have its own timer; leave that one.
|
||||
scheduleContexts.computeIfPresent(ruleArn, (arn, ctx) -> ctx.timerId() == timerId ? null : ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user