Clean up a bit

This commit is contained in:
Eugene Burmakin 2025-07-17 19:19:50 +02:00
parent eca09ce3eb
commit 10777714b1
3 changed files with 9 additions and 20 deletions

View file

@ -1,11 +1,6 @@
# frozen_string_literal: true
# Lightweight cleanup job that runs weekly to catch any missed track generation.
# This replaces the daily bulk creation job with a more targeted approach.
#
# Instead of processing all users daily, this job only processes users who have
# untracked points that are older than a threshold (e.g., 1 day), indicating
# they may have been missed by incremental processing.
#
# This provides a safety net while avoiding the overhead of daily bulk processing.
class Tracks::CleanupJob < ApplicationJob

View file

@ -1,7 +1,5 @@
# frozen_string_literal: true
# Simplified track generation service that replaces the complex strategy pattern.
#
# This service handles both bulk and incremental track generation using a unified
# approach with different modes:
#
@ -9,10 +7,6 @@
# - :incremental - Processes untracked points up to a specified end time
# - :daily - Processes tracks on a daily basis
#
# The service maintains the same core logic as the original system but simplifies
# the architecture by removing the multiple strategy classes in favor of
# mode-based configuration.
#
# Key features:
# - Deterministic results (same algorithm for all modes)
# - Simple incremental processing without buffering complexity
@ -62,9 +56,7 @@ class Tracks::Generator
def should_clean_tracks?
case mode
when :bulk then true
when :daily then true
when :incremental then false
when :bulk, :daily then true
else false
end
end
@ -82,6 +74,7 @@ class Tracks::Generator
def load_bulk_points
scope = user.tracked_points.order(:timestamp)
scope = scope.where(timestamp: time_range) if time_range_defined?
scope
end
@ -90,11 +83,13 @@ class Tracks::Generator
# If end_at is specified, only process points up to that time
scope = user.tracked_points.where(track_id: nil).order(:timestamp)
scope = scope.where(timestamp: ..end_at.to_i) if end_at.present?
scope
end
def load_daily_points
day_range = daily_time_range
user.tracked_points.where(timestamp: day_range).order(:timestamp)
end
@ -128,10 +123,10 @@ class Tracks::Generator
def clean_existing_tracks
case mode
when :bulk
clean_bulk_tracks
when :daily
clean_daily_tracks
when :bulk then clean_bulk_tracks
when :daily then clean_daily_tracks
else
raise ArgumentError, "Unknown mode: #{mode}"
end
end

View file

@ -15,12 +15,11 @@ class CreateTracksFromPoints < ActiveRecord::Migration[8.0]
# Use explicit parameters for bulk historical processing:
# - No time limits (start_at: nil, end_at: nil) = process ALL historical data
# - Replace strategy = clean slate, removes any existing tracks first
Tracks::CreateJob.perform_later(
user.id,
start_at: nil,
end_at: nil,
mode: :daily
mode: :bulk
)
processed_users += 1