@@ -186,15 +186,16 @@ def _single_item_upload(
186186 id_mapping : dict [str , str ],
187187 cache_directory : pathlib .Path ,
188188 thread_lock : threading .Lock ,
189- simvue_monitor_run : SimvueRun ,
189+ simvue_monitor_run : SimvueRun | None ,
190190 * ,
191191 throw_exceptions : bool = False ,
192192 retry_failed : bool = False ,
193193 upload_status : dict [str , str | float ] | None ,
194194 ) -> None :
195195 """Upload a single item of this object type."""
196196 _label : str = cls .object_type [:- 1 ] if cls .singular_object else cls .object_type
197- simvue_monitor_run .log_event (f"Uploading { _label } '{ identifier } '" )
197+ if simvue_monitor_run :
198+ simvue_monitor_run .log_event (f"Uploading { _label } '{ identifier } '" )
198199 _json_file = cache_directory .joinpath (f"{ cls .object_type } /{ identifier } .json" )
199200
200201 with _json_file .open () as in_f :
@@ -230,10 +231,11 @@ def _single_item_upload(
230231 _exception_msg : str = (
231232 f"Error while committing { _label } '{ identifier } ': { err } "
232233 )
233- simvue_monitor_run .log_event (_exception_msg )
234- simvue_monitor_run .log_alert (
235- name = "sender_object_upload_failure" , state = "critical"
236- )
234+ if simvue_monitor_run :
235+ simvue_monitor_run .log_event (_exception_msg )
236+ simvue_monitor_run .log_alert (
237+ name = "sender_object_upload_failure" , state = "critical"
238+ )
237239 cls .logger .error (_exception_msg )
238240 cls ._log_upload_failed (cache_directory , identifier , _data )
239241 return
@@ -266,9 +268,10 @@ def _single_item_upload(
266268 with thread_lock :
267269 upload_status .setdefault (cls .object_type , 0 )
268270 upload_status [cls .object_type ] += 1
269- simvue_monitor_run .log_metrics (
270- {f"uploads.{ cls .object_type } " : upload_status [cls .object_type ]}
271- )
271+ if simvue_monitor_run :
272+ simvue_monitor_run .log_metrics (
273+ {f"uploads.{ cls .object_type } " : upload_status [cls .object_type ]}
274+ )
272275
273276 cls .post_tasks (
274277 offline_id = identifier ,
@@ -285,7 +288,7 @@ def upload(
285288 thread_lock : threading .Lock ,
286289 threading_threshold : int ,
287290 max_thread_workers : int ,
288- simvue_monitor_run : SimvueRun ,
291+ simvue_monitor_run : SimvueRun | None ,
289292 * ,
290293 throw_exceptions : bool = False ,
291294 retry_failed : bool = False ,
@@ -306,6 +309,8 @@ def upload(
306309 the number of cached files above which threading will be used.
307310 max_thread_workers : int
308311 the maximum number of threads to use.
312+ simvue_monitor_run : SimvueRun | None
313+ run to track uploading
309314 throw_exceptions : bool, optional
310315 whether to throw exceptions and terminate, default False.
311316 retry_failed : bool, optional
@@ -934,7 +939,7 @@ def _single_item_upload(
934939 id_mapping : dict [str , str ],
935940 cache_directory : pathlib .Path ,
936941 thread_lock : threading .Lock ,
937- simvue_monitor_run : SimvueRun ,
942+ simvue_monitor_run : SimvueRun | None ,
938943 * ,
939944 throw_exceptions : bool = False ,
940945 retry_failed : bool = False ,
@@ -1032,7 +1037,7 @@ def _single_item_upload(
10321037 id_mapping : dict [str , str ],
10331038 cache_directory : pathlib .Path ,
10341039 thread_lock : threading .Lock ,
1035- simvue_monitor_run : SimvueRun ,
1040+ simvue_monitor_run : SimvueRun | None ,
10361041 * ,
10371042 throw_exceptions : bool = False ,
10381043 retry_failed : bool = False ,
@@ -1057,7 +1062,7 @@ def upload(
10571062 throw_exceptions : bool = False ,
10581063 retry_failed : bool = False ,
10591064 upload_status : dict [str , str | float ] | None = None ,
1060- simvue_monitor_run : dict [ str , str | float ] | None = None ,
1065+ simvue_monitor_run : SimvueRun | None = None ,
10611066 ) -> None :
10621067 """Upload CO2 intensity data."""
10631068 _ = id_mapping
0 commit comments