2 Commits

Author SHA1 Message Date
f9102c1a5d update vehicles in batches 2026-03-26 22:10:32 -04:00
0aef1d0c2b Build vehicle name 2026-03-26 12:45:17 -04:00
2 changed files with 14 additions and 3 deletions

View File

@@ -32,7 +32,7 @@ class VehicleVinDecodeJob < ApplicationJob
model: details.model.presence || vehicle.model,
doors: details.doors.presence || vehicle.doors,
trim: details.trim.presence || vehicle.trim,
name: vehicle.to_s,
name: build_name(vehicle, details),
vin_decoded: true,
error: nil
)
@@ -40,6 +40,15 @@ class VehicleVinDecodeJob < ApplicationJob
private
def build_name(vehicle, details)
if details.year && details.make && details.model
suffix = vehicle.vin.to_s[9..]
"#{details.year} #{details.make} #{details.model} - #{suffix}"
else
vehicle.vin
end
end
def log(msg)
Rails.logger.info "[VehicleVinDecodeJob] #{msg}"
end

View File

@@ -19,8 +19,10 @@ class AddPollingAndIndexes < ActiveRecord::Migration[7.0]
add_index :vehicles, :model
add_index :vehicles, :year
Vehicle.all.each do |v|
VehicleVinDecodeJob.perform_later(v.id)
Vehicle.find_each.with_index do |vehicle, index|
VehicleVinDecodeJob
.set(wait: (index / 50).minutes)
.perform_later(vehicle.id)
end
end