Created
June 28, 2019 13:59
-
-
Save Tocacar/f5ac7224db4f8709c4e0cdecbe69eb58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BankHolidayUpdateWorker | |
DataRetrievalError = Class.new(StandardError) | |
include Sidekiq::Worker | |
include Sidekiq::Status::Worker | |
UPDATE_INTERVAL = 2.days | |
def perform | |
return true if last_updated.updated_at > UPDATE_INTERVAL.ago | |
return last_updated.touch if stored_data_current? | |
lastest_data.save! | |
end | |
def last_updated | |
@last_updated ||= BankHoliday.by_updated_at.last | |
end | |
def lastest_data | |
@lastest_data ||= begin | |
bank_holiday = BankHoliday.new | |
bank_holiday.populate_dates | |
bank_holiday | |
end | |
end | |
def stored_data_current? | |
last_updated.dates == lastest_data.dates | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment