Skip to content

Commit

Permalink
Merge pull request #1538 from chrisccerami/fallback_to_server_time_if…
Browse files Browse the repository at this point in the history
…_redis_time_wont_work

Fallback to server time if Redis time won't work
  • Loading branch information
Chris C Cerami committed Feb 20, 2017
2 parents ac5c3de + a3c2ae1 commit af696b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -18,4 +18,4 @@ gem "minitest", "4.7.0"
gem "mocha", :require => false
gem "rack-test", "~> 0.5"
gem "rake"

gem "pry"
21 changes: 14 additions & 7 deletions lib/resque/data_store.rb
Expand Up @@ -7,11 +7,12 @@ class DataStore
HEARTBEAT_KEY = "workers:heartbeat"

def initialize(redis)
@redis = redis
@queue_access = QueueAccess.new(@redis)
@failed_queue_access = FailedQueueAccess.new(@redis)
@workers = Workers.new(@redis)
@stats_access = StatsAccess.new(@redis)
@redis = redis
@queue_access = QueueAccess.new(@redis)
@failed_queue_access = FailedQueueAccess.new(@redis)
@workers = Workers.new(@redis)
@stats_access = StatsAccess.new(@redis)
@redis_time_available = redis_time_available?
end

def_delegators :@queue_access, :push_to_queue,
Expand Down Expand Up @@ -91,10 +92,17 @@ def all_resque_keys
end

def server_time
time, _ = @redis.time
time, _ = @redis_time_available ? @redis.time : Time.now
Time.at(time)
end

def redis_time_available?
@redis.time
rescue Redis::CommandError
false
end
private :redis_time_available?

class QueueAccess
def initialize(redis)
@redis = redis
Expand Down Expand Up @@ -299,7 +307,6 @@ def redis_key_for_worker(worker)
def redis_key_for_worker_start_time(worker)
"#{redis_key_for_worker(worker)}:started"
end

end

class StatsAccess
Expand Down

0 comments on commit af696b9

Please sign in to comment.