Class: TopPostsSpiderJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/top_posts_spider_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(mode = 'recent') ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/jobs/top_posts_spider_job.rb', line 4

def perform(mode = 'recent')
  case mode.to_s
  when 'month'
    (1.month.ago.to_i..Time.now.to_i).step(1.day).each do |from|
      from = Time.at(from).beginning_of_day
      to = from.end_of_day
      set_top_between(from, to)
    end
  when 'recent'
    to = Post.maximum(:created_at) || Time.zone.now

    from = to - 1.day

    set_top_between(from, to)
  end
end