mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
- Oil analysis: Blackstone PDF import (20 elements, oil properties, universal averages), results stored per element, oil type, "leave out of trends", the original app's statuses; AvLab fixes (multi-line comments, unrelated labels no longer steal values). Existing records migrate. - Aircraft archives in the original app's .sam.zip format (schema v2): export from Access & Sharing, background import from the Fleet page, rake tasks. Archives move both ways between this app and the original. - Scanned logbook pages (images or PDFs) upload as a document; with ANTHROPIC_API_KEY set, Claude transcribes them into logbook entries. - Fix: deleting a component or aircraft failed when AD compliances or inspection records pointed at a component. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
25 lines
1.3 KiB
Ruby
25 lines
1.3 KiB
Ruby
# Imports a staged .sam.zip (see AircraftArchive::Importer) and records the outcome.
|
|
class AircraftImportJob < ApplicationJob
|
|
queue_as :default
|
|
|
|
def perform(import_id)
|
|
import = AircraftImport.find_by(id: import_id) or return
|
|
return unless import.status == "queued"
|
|
import.update!(status: "running", started_at: Time.current)
|
|
|
|
result = import.archive.open do |file|
|
|
AircraftArchive::Importer.new(file.path, owner: import.user, tail_number: import.tail_number,
|
|
progress: ->(counts) { import.update_columns(counts: counts, updated_at: Time.current) }).run
|
|
end
|
|
import.update!(status: "done", finished_at: Time.current, aircraft: result[:aircraft],
|
|
counts: result[:counts], warnings: result[:warnings].first(200))
|
|
rescue AircraftArchive::Error => e
|
|
import&.update!(status: "failed", finished_at: Time.current, error: e.message)
|
|
rescue StandardError => e
|
|
import&.update!(status: "failed", finished_at: Time.current, error: "Import failed: #{e.class}: #{e.message}".truncate(1000))
|
|
Rails.logger.error("[aircraft import] #{e.class}: #{e.message}\n#{e.backtrace&.first(10)&.join("\n")}")
|
|
ensure
|
|
import&.archive&.purge_later if import&.reload&.status.in?(%w[done failed])
|
|
end
|
|
end
|