Skip to content

Commit

Permalink
Update handling old time stored in redis
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejbartas committed Aug 15, 2018
1 parent 93c8c0f commit ce364db
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/sidekiq/cron/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Job
#how long we would like to store informations about previous enqueues
REMEMBER_THRESHOLD = 24 * 60 * 60
LAST_ENQUEUE_TIME_FORMAT = '%Y-%m-%d %H:%M:%S %z'
LAST_ENQUEUE_TIME_FORMAT_OLD = '%Y-%m-%d %H:%M:%S'

#crucial part of whole enquing job
def should_enque? time
Expand Down Expand Up @@ -552,6 +553,8 @@ def parse_args(args)

def parse_enqueue_time(timestamp)
DateTime.strptime(timestamp, LAST_ENQUEUE_TIME_FORMAT).to_time.utc
rescue ArgumentError
DateTime.strptime(timestamp, LAST_ENQUEUE_TIME_FORMAT_OLD).to_time.utc
end

def not_past_scheduled_time?(current_time)
Expand Down
22 changes: 22 additions & 0 deletions test/unit/job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,28 @@
end
end

describe 'parse_enqueue_time' do
before do
@args = {
name: "Test",
cron: "* * * * *"
}
@job = Sidekiq::Cron::Job.new(@args)
end

it 'should correctly parse new format' do
assert_equal @job.send(:parse_enqueue_time, '2017-01-02 15:23:43 UTC'), Time.new(2017, 1, 2, 15, 23, 43, '+00:00')
end

it 'should correctly parse new format with different timezone' do
assert_equal @job.send(:parse_enqueue_time, '2017-01-02 15:23:43 +01:00'), Time.new(2017, 1, 2, 15, 23, 43, '+01:00')
end

it 'should correctly parse old format' do
assert_equal @job.send(:parse_enqueue_time, '2017-01-02 15:23:43'), Time.new(2017, 1, 2, 15, 23, 43, '+00:00')
end
end

describe 'formatted time' do
before do
@args = {
Expand Down

0 comments on commit ce364db

Please sign in to comment.