Class: RailsPulse::SummaryJob

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

Instance Method Summary collapse

Instance Method Details

#perform(target_hour = nil) ⇒ Object



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
# File 'app/jobs/rails_pulse/summary_job.rb', line 3

def perform(target_hour = nil)
  target_hour ||= 1.hour.ago.beginning_of_hour

  # Always run hourly summary
  process_hourly_summary(target_hour)

  # Check if we should run daily summary (at the start of a new day)
  if target_hour.hour == 0
    process_daily_summary(target_hour.to_date - 1.day)

    # Check if we should run weekly summary (Monday at midnight)
    if target_hour.wday == 1
      process_weekly_summary((target_hour.to_date - 1.week).beginning_of_week)
    end

    # Check if we should run monthly summary (first day of month)
    if target_hour.day == 1
      process_monthly_summary((target_hour.to_date - 1.month).beginning_of_month)
    end
  end
rescue => e
  Rails.logger.error "[RailsPulse] Summary job failed: #{e.message}"
  Rails.logger.error e.backtrace.join("\n")
  raise
end