# frozen_string_literal: true # Background job to consolidate completed hour into day file # Runs at :05 past each hour (e.g., 01:05, 02:05, etc.) # Merges the previous hour's data into the day file and deletes the hour file class ConsolidateParquetHourlyJob < ApplicationJob queue_as :default def perform service = AnalyticsDuckdbService.instance # Consolidate the previous hour (not current hour, which is still being written) previous_hour = 1.hour.ago Rails.logger.info "[Parquet Consolidate] Starting hourly consolidation for #{previous_hour.strftime('%Y-%m-%d %H:00')}" service.consolidate_hour_to_day(previous_hour) Rails.logger.info "[Parquet Consolidate] Hourly consolidation complete" rescue StandardError => e Rails.logger.error "[Parquet Consolidate] Hourly job failed: #{e.message}" Rails.logger.error e.backtrace.join("\n") raise # Re-raise to mark job as failed in Solid Queue end end