6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'app/jobs/lato_storage/preload_dashboard_data_job.rb', line 6
def perform(force_execution = false)
return load_data_without_optimizations unless LatoStorage.config.optimize_performances
data = Rails.cache.read(DATA_CACHE_KEY)
return data || {} if Rails.cache.read(SEMAPHORE_CACHE_KEY)
if data && !force_execution
LatoStorage::PreloadDashboardDataJob.perform_later(true)
return data
end
Rails.cache.write(SEMAPHORE_CACHE_KEY, true, expires_in: 30.minutes)
data = load_data_with_optimizations
Rails.cache.write(DATA_CACHE_KEY, data, expires_in: 12.hours)
return data
rescue StandardError => e
Rails.logger.error "Error in LatoStorage::PreloadDashboardDataJob: #{e.message}"
Rails.logger.error e.backtrace.join("\n")
Rails.cache.delete(SEMAPHORE_CACHE_KEY)
nil
end
|