2025-03-07 17:32:56 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
class BulkVisitsSuggestingJob < ApplicationJob
|
|
|
|
|
queue_as :default
|
|
|
|
|
sidekiq_options retry: false
|
|
|
|
|
|
|
|
|
|
# Passing timespan of more than 3 years somehow results in duplicated Places
|
|
|
|
|
def perform(start_at:, end_at:, user_ids: [])
|
|
|
|
|
users = user_ids.any? ? User.where(id: user_ids) : User.all
|
|
|
|
|
start_at = start_at.to_datetime
|
|
|
|
|
end_at = end_at.to_datetime
|
|
|
|
|
|
2025-03-09 09:58:30 -04:00
|
|
|
time_chunks = Visits::TimeChunks.new(start_at:, end_at:).call
|
2025-03-07 17:32:56 -05:00
|
|
|
|
|
|
|
|
users.active.find_each do |user|
|
|
|
|
|
next if user.tracked_points.empty?
|
|
|
|
|
|
2025-03-09 09:58:30 -04:00
|
|
|
schedule_chunked_jobs(user, time_chunks)
|
2025-03-07 17:32:56 -05:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
2025-03-09 09:58:30 -04:00
|
|
|
def schedule_chunked_jobs(user, time_chunks)
|
|
|
|
|
time_chunks.each do |time_chunk|
|
|
|
|
|
VisitSuggestingJob.perform_later(
|
|
|
|
|
user_id: user.id, start_at: time_chunk.first, end_at: time_chunk.last
|
|
|
|
|
)
|
2025-03-07 17:32:56 -05:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|