Skip to content

Commit c5f6f8c

Browse files
Revert PR #53 for backfilling scheduled jobs (#57)
* Revert "Backfill scheduled jobs if they are missing within the queue ahead time (#53)" This reverts commit 1f90f7a. * Bump version to 1.1.1 for immediate release * Maintain requirement of :at option in config file for future changes
1 parent a0c29af commit c5f6f8c

File tree

4 files changed

+11
-61
lines changed

4 files changed

+11
-61
lines changed

lib/simple_scheduler/scheduler_job.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def load_config
2929
def queue_future_jobs
3030
tasks.each do |task|
3131
# Schedule the new run times using the future job wrapper.
32-
task.future_run_times.each do |time|
32+
new_run_times = task.future_run_times - task.existing_run_times
33+
new_run_times.each do |time|
3334
SimpleScheduler::FutureJob.set(queue: @queue_name, wait_until: time)
3435
.perform_later(task.params, time.to_i)
3536
end

lib/simple_scheduler/task.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,17 @@ def frequency
6565
# @return [Array<Time>]
6666
# rubocop:disable Metrics/AbcSize
6767
def future_run_times
68-
last_run_time = at - frequency
68+
future_run_times = existing_run_times.dup
69+
last_run_time = future_run_times.last || at - frequency
6970
last_run_time = last_run_time.in_time_zone(time_zone)
70-
future_run_times = []
7171

7272
# Ensure there are at least two future jobs scheduled and that the queue ahead time is filled
73-
while (future_run_times + existing_run_times).length < 2 || minutes_queued_ahead(last_run_time) < queue_ahead
73+
while future_run_times.length < 2 || minutes_queued_ahead(last_run_time) < queue_ahead
7474
last_run_time = frequency.from_now(last_run_time)
7575
# The hour may not match because of a shift caused by DST in previous run times,
7676
# so we need to ensure that the hour matches the specified hour if given.
7777
last_run_time = last_run_time.change(hour: at.hour, min: at.min) if at.hour?
78-
future_run_times << last_run_time unless existing_run_times.include?(last_run_time)
78+
future_run_times << last_run_time
7979
end
8080

8181
future_run_times

lib/simple_scheduler/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module SimpleScheduler
2-
VERSION = "1.1.0".freeze
2+
VERSION = "1.1.1".freeze
33
end

spec/simple_scheduler/task_spec.rb

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,12 @@
342342

343343
it "won't be rescheduled when the time falls back if the job was previously executed" do
344344
travel_to Time.parse("2016-11-06 01:00:00 CST") do
345-
expect(task).to receive(:existing_run_times).at_least(:once).and_return([
346-
Time.parse("2016-11-07 01:30:00 CST")
345+
tomorrows_run_time = Time.parse("2016-11-07 01:30:00 CST")
346+
expect(task).to receive(:existing_jobs).and_return([
347+
Sidekiq::SortedEntry.new(nil, tomorrows_run_time.to_i, "wrapped" => "TestJob", "class" => "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper")
347348
])
348349
expect(task.future_run_times).to eq([
350+
Time.parse("2016-11-07 01:30:00 CST"),
349351
Time.parse("2016-11-08 01:30:00 CST")
350352
])
351353
end
@@ -438,58 +440,5 @@
438440
end
439441
end
440442
end
441-
442-
context "when there are existing run times" do
443-
let(:task) do
444-
described_class.new(
445-
class: "TestJob",
446-
every: "15.minutes",
447-
at: "*:00",
448-
queue_ahead: 60, # minutes
449-
tz: "America/Chicago"
450-
)
451-
end
452-
453-
it "only returns the run times that need to be added to the queue" do
454-
travel_to Time.parse("2016-12-01 20:00:00 CST") do
455-
expect(task).to receive(:existing_run_times).at_least(:once).and_return([
456-
Time.parse("2016-12-01 20:00:00 CST"),
457-
Time.parse("2016-12-01 20:15:00 CST"),
458-
Time.parse("2016-12-01 20:30:00 CST")
459-
])
460-
expect(task.future_run_times).to eq([
461-
Time.parse("2016-12-01 20:45:00 CST"),
462-
Time.parse("2016-12-01 21:00:00 CST")
463-
])
464-
end
465-
end
466-
end
467-
468-
context "when an existing run time is deleted" do
469-
let(:task) do
470-
described_class.new(
471-
class: "TestJob",
472-
every: "15.minutes",
473-
at: "*:00",
474-
queue_ahead: 60, # minutes
475-
tz: "America/Chicago"
476-
)
477-
end
478-
479-
it "includes in the missing run time" do
480-
travel_to Time.parse("2016-12-01 20:00:00 CST") do
481-
expect(task).to receive(:existing_run_times).at_least(:once).and_return([
482-
Time.parse("2016-12-01 20:00:00 CST"),
483-
# Time.parse("2016-12-01 20:15:00 CST"), <-- The missing run time
484-
Time.parse("2016-12-01 20:30:00 CST")
485-
])
486-
expect(task.future_run_times).to eq([
487-
Time.parse("2016-12-01 20:15:00 CST"), # <-- The missing run time
488-
Time.parse("2016-12-01 20:45:00 CST"),
489-
Time.parse("2016-12-01 21:00:00 CST")
490-
])
491-
end
492-
end
493-
end
494443
end
495444
end

0 commit comments

Comments
 (0)