Class: Jobs::AggregateWebHooksEvents

Inherits:
Scheduled show all
Defined in:
app/jobs/scheduled/aggregate_web_hooks_events.rb

Instance Method Summary collapse

Methods inherited from Scheduled

#perform

Methods inherited from Base

acquire_cluster_concurrency_lock!, clear_cluster_concurrency_lock!, cluster_concurrency, cluster_concurrency_redis_key, delayed_perform, #error_context, get_cluster_concurrency, #last_db_duration, #log, #perform, #perform_immediately

Instance Method Details

#execute(args = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/jobs/scheduled/aggregate_web_hooks_events.rb', line 7

def execute(args = {})
  date = args[:date].present? ? args[:date] : Time.zone.now.to_date
  WebHook
    .joins(
      "LEFT JOIN web_hook_events_daily_aggregates ON web_hooks.id = web_hook_events_daily_aggregates.web_hook_id AND web_hook_events_daily_aggregates.date = '#{date}'",
    )
    .where(active: true)
    .where(web_hook_events_daily_aggregates: { id: nil })
    .distinct
    .each do |web_hook|
      WebHookEventsDailyAggregate.create!(web_hook_id: web_hook.id, date: date)
    end
end