@@ -137,42 +137,37 @@ async def store_into_file(
137
137
dirname = os .path .dirname (fname )
138
138
os .makedirs (dirname , exist_ok = True )
139
139
140
- main_media_repo_write_trace_scope = start_active_span (
141
- "writing to main media repo"
142
- )
143
- main_media_repo_write_trace_scope .__enter__ ()
144
-
145
- with main_media_repo_write_trace_scope :
146
- try :
140
+ try :
141
+ with start_active_span ("writing to main media repo" ):
147
142
with open (fname , "wb" ) as f :
148
143
yield f , fname
149
144
150
- except Exception as e :
151
- try :
152
- os .remove (fname )
153
- except Exception :
154
- pass
155
-
156
- raise e from None
157
-
158
- with start_active_span ("writing to other storage providers" ):
159
- spam_check = (
160
- await self ._spam_checker_module_callbacks .check_media_file_for_spam (
161
- ReadableFileWrapper (self .clock , fname ), file_info
145
+ with start_active_span ("writing to other storage providers" ):
146
+ spam_check = (
147
+ await self ._spam_checker_module_callbacks .check_media_file_for_spam (
148
+ ReadableFileWrapper (self .clock , fname ), file_info
149
+ )
162
150
)
163
- )
164
- if spam_check != self ._spam_checker_module_callbacks .NOT_SPAM :
165
- logger .info ("Blocking media due to spam checker" )
166
- # Note that we'll delete the stored media, due to the
167
- # try/except below. The media also won't be stored in
168
- # the DB.
169
- # We currently ignore any additional field returned by
170
- # the spam-check API.
171
- raise SpamMediaException (errcode = spam_check [0 ])
172
-
173
- for provider in self .storage_providers :
174
- with start_active_span (str (provider )):
175
- await provider .store_file (path , file_info )
151
+ if spam_check != self ._spam_checker_module_callbacks .NOT_SPAM :
152
+ logger .info ("Blocking media due to spam checker" )
153
+ # Note that we'll delete the stored media, due to the
154
+ # try/except below. The media also won't be stored in
155
+ # the DB.
156
+ # We currently ignore any additional field returned by
157
+ # the spam-check API.
158
+ raise SpamMediaException (errcode = spam_check [0 ])
159
+
160
+ for provider in self .storage_providers :
161
+ with start_active_span (str (provider )):
162
+ await provider .store_file (path , file_info )
163
+
164
+ except Exception as e :
165
+ try :
166
+ os .remove (fname )
167
+ except Exception :
168
+ pass
169
+
170
+ raise e from None
176
171
177
172
async def fetch_media (self , file_info : FileInfo ) -> Optional [Responder ]:
178
173
"""Attempts to fetch media described by file_info from the local cache
0 commit comments