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
|
2024-10-03 09:33:31 -04:00
|
|
|
sidekiq_options retry: false
|
2024-08-05 15:23:08 -04:00
|
|
|
|
2025-03-07 17:32:56 -05: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
|
|
|
|
2025-03-07 17:32:56 -05:00
|
|
|
time_chunks = (start_at..end_at).step(1.day).to_a
|
2025-01-09 07:38:13 -05:00
|
|
|
|
2025-03-07 17:32:56 -05:00
|
|
|
time_chunks.each do |time_chunk|
|
|
|
|
|
Visits::Suggest.new(user, start_at: time_chunk, end_at: time_chunk + 1.day).call
|
2025-01-09 07:38:13 -05:00
|
|
|
end
|
2024-08-05 15:23:08 -04:00
|
|
|
end
|
|
|
|
|
end
|