mirror of
https://github.com/endofunky/sidetiq.git
synced 2022-11-09 13:53:30 -05:00
Don't inherit from IceCube::Schedule.
This commit is contained in:
parent
60b7db60e7
commit
bdb6babe30
6 changed files with 51 additions and 19 deletions
|
@ -7,6 +7,7 @@ HEAD
|
||||||
- Add `Sidetiq.retries`.
|
- Add `Sidetiq.retries`.
|
||||||
- Add `Sidetiq.logger`. This defaults to the Sidekiq logger.
|
- Add `Sidetiq.logger`. This defaults to the Sidekiq logger.
|
||||||
- Clean up tests.
|
- Clean up tests.
|
||||||
|
- Sidetiq::Schedule no longer inherits from IceCube::Schedule.
|
||||||
|
|
||||||
0.2.0
|
0.2.0
|
||||||
-----
|
-----
|
||||||
|
|
|
@ -11,10 +11,6 @@ module Sidetiq
|
||||||
include Singleton
|
include Singleton
|
||||||
include MonitorMixin
|
include MonitorMixin
|
||||||
|
|
||||||
# Public: Start time offset from epoch used for calculating run
|
|
||||||
# times in the Sidetiq schedules.
|
|
||||||
START_TIME = Sidetiq.config.utc ? Time.utc(2010, 1, 1) : Time.local(2010, 1, 1)
|
|
||||||
|
|
||||||
# Internal: Returns a hash of Sidetiq::Schedule instances.
|
# Internal: Returns a hash of Sidetiq::Schedule instances.
|
||||||
attr_reader :schedules
|
attr_reader :schedules
|
||||||
|
|
||||||
|
@ -41,7 +37,7 @@ module Sidetiq
|
||||||
#
|
#
|
||||||
# Returns a Sidetiq::Schedule instances.
|
# Returns a Sidetiq::Schedule instances.
|
||||||
def schedule_for(worker)
|
def schedule_for(worker)
|
||||||
schedules[worker] ||= Sidetiq::Schedule.new(START_TIME)
|
schedules[worker] ||= Sidetiq::Schedule.new
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Issue a single clock tick.
|
# Public: Issue a single clock tick.
|
||||||
|
|
|
@ -12,10 +12,12 @@ module Sidetiq
|
||||||
# end
|
# end
|
||||||
module Schedulable
|
module Schedulable
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
|
# Public: Returns a Float timestamp of the last scheduled run.
|
||||||
def last_scheduled_occurrence
|
def last_scheduled_occurrence
|
||||||
get_timestamp "last"
|
get_timestamp "last"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Public: Returns a Float timestamp of the next scheduled run.
|
||||||
def next_scheduled_occurrence
|
def next_scheduled_occurrence
|
||||||
get_timestamp "next"
|
get_timestamp "next"
|
||||||
end
|
end
|
||||||
|
@ -41,3 +43,4 @@ module Sidetiq
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,59 @@
|
||||||
module Sidetiq
|
module Sidetiq
|
||||||
# Internal: Recurrence schedules.
|
# Public: Recurrence schedule.
|
||||||
class Schedule < IceCube::Schedule
|
class Schedule
|
||||||
def method_missing(meth, *args, &block)
|
# Public: Start time offset from epoch used for calculating run
|
||||||
|
# times in the Sidetiq schedules.
|
||||||
|
START_TIME = Sidetiq.config.utc ? Time.utc(2010, 1, 1) : Time.local(2010, 1, 1)
|
||||||
|
|
||||||
|
def initialize # :nodoc:
|
||||||
|
@schedule = IceCube::Schedule.new(START_TIME)
|
||||||
|
end
|
||||||
|
|
||||||
|
def method_missing(meth, *args, &block) # :nodoc:
|
||||||
if IceCube::Rule.respond_to?(meth)
|
if IceCube::Rule.respond_to?(meth)
|
||||||
rule = IceCube::Rule.send(meth, *args, &block)
|
rule = IceCube::Rule.send(meth, *args, &block)
|
||||||
add_recurrence_rule(rule)
|
@schedule.add_recurrence_rule(rule)
|
||||||
rule
|
rule
|
||||||
|
elsif @schedule.respond_to?(meth)
|
||||||
|
@schedule.send(meth, *args, &block)
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Public: Checks if a job is due to be scheduled.
|
||||||
|
#
|
||||||
|
# Returns true if a job is due, otherwise false.
|
||||||
def schedule_next?(time)
|
def schedule_next?(time)
|
||||||
if @last_scheduled != (no = next_occurrence(time))
|
next_occurrence = @schedule.next_occurrence(time)
|
||||||
@last_scheduled = no
|
if @last_scheduled != next_occurrence
|
||||||
|
@last_scheduled = next_occurrence
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Public: Schedule to String.
|
||||||
|
#
|
||||||
|
# Examples
|
||||||
|
#
|
||||||
|
# class MyWorker
|
||||||
|
# include Sidekiq::Worker
|
||||||
|
# include Sidetiq::Schedulable
|
||||||
|
#
|
||||||
|
# tiq { daily }
|
||||||
|
#
|
||||||
|
# def perform
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# Sidetiq.schedules[MyWorker].to_s
|
||||||
|
# # => "Daily"
|
||||||
|
#
|
||||||
|
# Returns a String representing the schedule.
|
||||||
|
def to_s
|
||||||
|
@schedule.to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ class TestClock < Sidetiq::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_enqueues_jobs_by_schedule
|
def test_enqueues_jobs_by_schedule
|
||||||
schedule = Sidetiq::Schedule.new(Sidetiq::Clock::START_TIME)
|
schedule = Sidetiq::Schedule.new
|
||||||
schedule.daily
|
schedule.daily
|
||||||
|
|
||||||
clock.stubs(:schedules).returns(SimpleWorker => schedule)
|
clock.stubs(:schedules).returns(SimpleWorker => schedule)
|
||||||
|
@ -60,7 +60,7 @@ class TestClock < Sidetiq::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_enqueues_jobs_with_default_last_tick_arg_on_first_run
|
def test_enqueues_jobs_with_default_last_tick_arg_on_first_run
|
||||||
schedule = Sidetiq::Schedule.new(Sidetiq::Clock::START_TIME)
|
schedule = Sidetiq::Schedule.new
|
||||||
schedule.hourly
|
schedule.hourly
|
||||||
|
|
||||||
time = Time.local(2011, 1, 1, 1, 30)
|
time = Time.local(2011, 1, 1, 1, 30)
|
||||||
|
@ -79,7 +79,7 @@ class TestClock < Sidetiq::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_enqueues_jobs_with_last_run_timestamp_and_next_run_timestamp
|
def test_enqueues_jobs_with_last_run_timestamp_and_next_run_timestamp
|
||||||
schedule = Sidetiq::Schedule.new(Sidetiq::Clock::START_TIME)
|
schedule = Sidetiq::Schedule.new
|
||||||
schedule.hourly
|
schedule.hourly
|
||||||
|
|
||||||
time = Time.local(2011, 1, 1, 1, 30)
|
time = Time.local(2011, 1, 1, 1, 30)
|
||||||
|
@ -98,7 +98,7 @@ class TestClock < Sidetiq::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_enqueues_jobs_correctly_for_splat_args_perform_methods
|
def test_enqueues_jobs_correctly_for_splat_args_perform_methods
|
||||||
schedule = Sidetiq::Schedule.new(Sidetiq::Clock::START_TIME)
|
schedule = Sidetiq::Schedule.new
|
||||||
schedule.hourly
|
schedule.hourly
|
||||||
|
|
||||||
time = Time.local(2011, 1, 1, 1, 30)
|
time = Time.local(2011, 1, 1, 1, 30)
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
require_relative 'helper'
|
require_relative 'helper'
|
||||||
|
|
||||||
class TestSchedule < Sidetiq::TestCase
|
class TestSchedule < Sidetiq::TestCase
|
||||||
def test_super
|
|
||||||
assert_equal IceCube::Schedule, Sidetiq::Schedule.superclass
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_method_missing
|
def test_method_missing
|
||||||
sched = Sidetiq::Schedule.new
|
sched = Sidetiq::Schedule.new
|
||||||
sched.daily
|
sched.daily
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue