23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'app/controllers/llm_cost_tracker/reconciliation_controller.rb', line 23
def trigger_import
unless LlmCostTracker::Reconciliation.enabled?
return redirect_to reconciliation_path, alert: "Reconciliation is disabled"
end
source = params[:source].to_s
importer = configured_importers[source.to_sym]
return redirect_to reconciliation_path, alert: "No importer configured for #{source}" if importer.nil?
result = importer.call
if result.respond_to?(:errors) && result.errors.any?
LlmCostTracker::Logging.warn(
"Reconciliation import for #{source} returned #{result.errors.size} row error(s)"
)
return redirect_to(
reconciliation_path,
alert: "Imported #{result.respond_to?(:total_imported) ? result.total_imported : 0} " \
"#{source} rows with #{result.errors.size} row error(s); see Rails logs for details."
)
end
message = if result.respond_to?(:total_imported)
"Imported #{result.total_imported} #{source} rows"
else
"Triggered #{source} importer"
end
redirect_to reconciliation_path, notice: message
rescue StandardError => e
LlmCostTracker::Logging.warn("Reconciliation import failed for #{source}: #{e.class}: #{e.message}")
redirect_to reconciliation_path,
alert: "Import failed (#{e.class.name}); see Rails logs for details."
end
|