dawarich/app/jobs/visit_suggesting_job.rb

29 lines
741 B
Ruby
Raw Normal View History

2024-08-12 16:18:11 -04:00
# frozen_string_literal: true
2024-08-05 15:23:08 -04:00
class VisitSuggestingJob < ApplicationJob
2024-09-08 10:52:35 -04:00
queue_as :visit_suggesting
2025-06-09 07:39:25 -04:00
sidekiq_options retry: false
2024-08-05 15:23:08 -04:00
# Passing timespan of more than 3 years somehow results in duplicated Places
def perform(user_id:, start_at:, end_at:)
user = User.find(user_id)
2024-08-12 16:18:11 -04:00
start_time = parse_date(start_at)
end_time = parse_date(end_at)
2025-01-09 07:38:13 -05:00
# Create one-day chunks
current_time = start_time
while current_time < end_time
chunk_end = [current_time + 1.day, end_time].min
Visits::Suggest.new(user, start_at: current_time, end_at: chunk_end).call
current_time += 1.day
2025-01-09 07:38:13 -05:00
end
2024-08-05 15:23:08 -04:00
end
private
def parse_date(date)
date.is_a?(String) ? Time.zone.parse(date) : date.to_datetime
end
2024-08-05 15:23:08 -04:00
end