0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-08 17:53:55 +08:00
discourse/app/jobs/scheduled/aggregate_web_hooks_events.rb
Jarek Radosz 09d07fc418
DEV: Enable Style/RedundantParentheses rubocop rule (#40095)
(to be enabled in the shared config)
2026-05-19 15:48:09 +02:00

21 lines
662 B
Ruby
Vendored

# frozen_string_literal: true
module Jobs
class AggregateWebHooksEvents < ::Jobs::Scheduled
every 1.day
def execute(args = {})
date = args[:date].presence || 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
end
end