@@ -220,38 +220,42 @@ defmodule Ret.Scene do
220
220
221
221
Repo . transaction ( fn ->
222
222
Enum . each ( scene_stream , fn scene ->
223
- % Scene {
224
- scene_owned_file: old_scene_owned_file ,
225
- model_owned_file: old_model_owned_file ,
226
- account: account
227
- } = scene
228
-
229
- new_scene_owned_file =
230
- Storage . create_new_owned_file_with_replaced_string (
231
- old_scene_owned_file ,
232
- account ,
233
- old_domain_url ,
234
- new_domain_url
235
- )
236
-
237
- { :ok , new_model_owned_file } =
238
- Storage . duplicate_and_transform ( old_model_owned_file , account , fn glb_stream ,
239
- _total_bytes ->
240
- GLTFUtils . replace_in_glb ( glb_stream , old_domain_url , new_domain_url )
241
- end )
242
-
243
- scene
244
- |> change ( )
245
- |> put_change ( :scene_owned_file_id , new_scene_owned_file . owned_file_id )
246
- |> put_change ( :model_owned_file_id , new_model_owned_file . owned_file_id )
247
- |> Repo . update! ( )
248
-
249
- for old_owned_file <- [ old_scene_owned_file , old_model_owned_file ] do
250
- OwnedFile . set_inactive ( old_owned_file )
251
- Storage . rm_files_for_owned_file ( old_owned_file )
252
- Repo . delete ( old_owned_file )
253
- end
254
- end )
223
+ try do
224
+ % Scene {
225
+ scene_owned_file: old_scene_owned_file ,
226
+ model_owned_file: old_model_owned_file ,
227
+ account: account
228
+ } = scene
229
+
230
+ new_scene_owned_file =
231
+ Storage . create_new_owned_file_with_replaced_string (
232
+ old_scene_owned_file ,
233
+ account ,
234
+ old_domain_url ,
235
+ new_domain_url
236
+ )
237
+
238
+ { :ok , new_model_owned_file } =
239
+ Storage . duplicate_and_transform ( old_model_owned_file , account , fn glb_stream ,
240
+ _total_bytes ->
241
+ GLTFUtils . replace_in_glb ( glb_stream , old_domain_url , new_domain_url )
242
+ end )
243
+
244
+ scene
245
+ |> change ( )
246
+ |> put_change ( :scene_owned_file_id , new_scene_owned_file . owned_file_id )
247
+ |> put_change ( :model_owned_file_id , new_model_owned_file . owned_file_id )
248
+ |> Repo . update! ( )
249
+
250
+ for old_owned_file <- [ old_scene_owned_file , old_model_owned_file ] do
251
+ OwnedFile . set_inactive ( old_owned_file )
252
+ Storage . rm_files_for_owned_file ( old_owned_file )
253
+ Repo . delete ( old_owned_file )
254
+ end
255
+ rescue
256
+ e ->
257
+ IO . warn ( "Failed to process scene due to an error: #{ inspect ( e ) } " )
258
+ end )
255
259
256
260
:ok
257
261
end )
0 commit comments