summaryrefslogtreecommitdiff
path: root/app/models/concerns/cron_schedulable.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/concerns/cron_schedulable.rb')
-rw-r--r--app/models/concerns/cron_schedulable.rb21
1 files changed, 13 insertions, 8 deletions
diff --git a/app/models/concerns/cron_schedulable.rb b/app/models/concerns/cron_schedulable.rb
index beb3a09c119..48605ecc3d7 100644
--- a/app/models/concerns/cron_schedulable.rb
+++ b/app/models/concerns/cron_schedulable.rb
@@ -4,23 +4,28 @@ module CronSchedulable
extend ActiveSupport::Concern
include Schedulable
+ def set_next_run_at
+ self.next_run_at = calculate_next_run_at
+ end
+
+ private
+
##
# The `next_run_at` column is set to the actual execution date of worker that
# triggers the schedule. This way, a schedule like `*/1 * * * *` won't be triggered
# in a short interval when the worker runs irregularly by Sidekiq Memory Killer.
- def set_next_run_at
+ def calculate_next_run_at
now = Time.zone.now
+
ideal_next_run = ideal_next_run_from(now)
- self.next_run_at = if ideal_next_run == cron_worker_next_run_from(now)
- ideal_next_run
- else
- cron_worker_next_run_from(ideal_next_run)
- end
+ if ideal_next_run == cron_worker_next_run_from(now)
+ ideal_next_run
+ else
+ cron_worker_next_run_from(ideal_next_run)
+ end
end
- private
-
def ideal_next_run_from(start_time)
next_time_from(start_time, cron, cron_timezone)
end