@@ -60,9 +60,12 @@ defmodule TransportWeb.ValidationController do
6060 end
6161 end
6262
63- # IRVE statique validation doesn’t use an Oban job and doesn’t store anything
64- # It’s just a display and forget validation, and it’s quick enough so that it can be done synchronously
65- # This clause intercepts the validation instead of sending to Validata like other TableSchema validations
63+ # This clause intercepts IRVE statique validation instead of routing it to Validata like the other
64+ # TableSchema validations, running it synchronously on the web server (which enables the permalink below)
65+ # rather than on a worker. The catch: it takes an order of magnitude more RAM than the raw CSV (at time of
66+ # writing), and the web node should stay isolated from that pressure to keep serving requests, so it would
67+ # be a good idea not to reproduce this pattern:
68+ # https://github.com/etalab/transport-site/pull/5524#pullrequestreview-4407262217
6669 def validate ( % Plug.Conn { } = conn , % {
6770 "upload" => % { "file" => % { path: file_path , filename: filename } , "type" => "etalab/schema-irve-statique" }
6871 } ) do
@@ -112,10 +115,18 @@ defmodule TransportWeb.ValidationController do
112115 defp validate_irve_statique ( conn , file_path , filename , _size ) do
113116 summary = Transport.IRVE.Validator . validate_and_summarize ( file_path , irve_extension ( filename ) )
114117
115- conn
116- |> assign ( :summary , summary )
117- |> assign ( :filename , filename || "upload.csv" )
118- |> render ( "show_irve_statique.html" )
118+ validation =
119+ % MultiValidation {
120+ validator: "on-demand-irve-statique" ,
121+ validation_timestamp: DateTime . utc_now ( ) ,
122+ # The #show route patterns match on secret_url_token
123+ oban_args: % { "type" => "irve-statique" , "state" => "completed" , "secret_url_token" => Ecto.UUID . generate ( ) } ,
124+ result: Map . from_struct ( summary ) ,
125+ validated_data_name: filename || "upload.csv"
126+ }
127+ |> Repo . insert! ( )
128+
129+ redirect_to_validation_show ( conn , validation )
119130 end
120131
121132 defp irve_extension ( filename ) when is_binary ( filename ) and filename != "" do
@@ -157,11 +168,7 @@ defmodule TransportWeb.ValidationController do
157168 validator = Transport.Validators.GTFSTransport
158169 current_issues = validator . get_issues ( validation . result , params )
159170
160- issue_type =
161- case params [ "issue_type" ] do
162- nil -> validator . issue_type ( current_issues )
163- issue_type -> issue_type
164- end
171+ issue_type = params [ "issue_type" ] || validator . issue_type ( current_issues )
165172
166173 conn
167174 |> assign_base_validation_details ( params )
@@ -201,6 +208,12 @@ defmodule TransportWeb.ValidationController do
201208 |> assign ( :xsd_errors , xsd_errors )
202209 |> render ( template )
203210
211+ % MultiValidation { oban_args: % { "state" => "completed" , "type" => "irve-statique" } } = validation ->
212+ conn
213+ |> assign ( :summary , Transport.IRVE.Validator.Summary . from_result ( validation . result ) )
214+ |> assign ( :filename , validation . validated_data_name )
215+ |> render ( "show_irve_statique.html" )
216+
204217 # Handles waiting for validation to complete, errors and
205218 # validation for schemas
206219 _ ->
0 commit comments