-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcache_refresh_job.rb
More file actions
39 lines (28 loc) · 912 Bytes
/
cache_refresh_job.rb
File metadata and controls
39 lines (28 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require 'logger'
require 'rufus-scheduler'
require './butler'
require './category'
CACHE_REFRESH_INTERVAL_DEFAULT = '120s'
TRENDING_COUNT_MOBILE = 6
TRENDING_COUNT_WEB = 12
logger = Logger.new(STDOUT)
scheduler = Rufus::Scheduler.new
butler = Butler.new(ENV['REDIS_URL_FULL'])
interval = ENV['CACHE_REFRESH_INTERVAL'] || CACHE_REFRESH_INTERVAL_DEFAULT
scheduler.every interval, first_in: '3s', overlap: false do
logger.info('Start update Redis cache')
# Popular cache (first page)
butler.popular(1)
# Trending today cache (web and mobile version)
date = Date.today.strftime('%Y-%m-%d')
butler.trending(date, TRENDING_COUNT_MOBILE)
butler.trending(date, TRENDING_COUNT_WEB)
# Categories cache (first page)
Category.all.each do |c|
butler.category(c.id, 1)
end
# Latest news today (all pages)
butler.latest(date, 0)
logger.info('End update Redis cache')
end
scheduler.join