mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-09 08:47:11 -05:00
25 lines
456 B
Ruby
25 lines
456 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Trips::CalculateDistanceJob < ApplicationJob
|
|
queue_as :default
|
|
|
|
def perform(trip_id)
|
|
trip = Trip.find(trip_id)
|
|
|
|
trip.calculate_distance
|
|
trip.save!
|
|
|
|
broadcast_update(trip)
|
|
end
|
|
|
|
private
|
|
|
|
def broadcast_update(trip)
|
|
Turbo::StreamsChannel.broadcast_update_to(
|
|
"trip_#{trip.id}",
|
|
target: "trip_distance",
|
|
partial: "trips/distance",
|
|
locals: { trip: trip }
|
|
)
|
|
end
|
|
end
|