@@ -144,7 +144,19 @@ def undef_metadata(self, filename):
144
144
info ["SENSOR" ] = "S??"
145
145
return info
146
146
147
- def transmit_status (self , metadata , code , description ):
147
+ async def print_msg (self , msg ):
148
+ """Print message dictionary - used if a CSC has not been created
149
+
150
+ Parameters
151
+ ----------
152
+ msg: `dict`
153
+ Dictionary to print
154
+ """
155
+
156
+ LOGGER .info (f"would have sent { msg = } " )
157
+ await asyncio .sleep (0 )
158
+
159
+ async def transmit_status (self , metadata , code , description ):
148
160
"""Transmit a message with given metadata, status code and description
149
161
150
162
Parameters
@@ -162,10 +174,14 @@ def transmit_status(self, metadata, code, description):
162
174
msg ["DESCRIPTION" ] = description
163
175
LOGGER .info ("msg: %s, code: %s, description: %s" , msg , code , description )
164
176
if self .csc is None :
177
+ await self .print_msg (msg )
165
178
return
166
- asyncio . run ( self .csc .send_imageInOODS (msg ) )
179
+ await self .csc .send_imageInOODS (msg )
167
180
168
181
def on_success (self , datasets ):
182
+ asyncio .create_task (self ._on_success (datasets ))
183
+
184
+ async def _on_success (self , datasets ):
169
185
"""Callback used on successful ingest. Used to transmit
170
186
successful data ingestion status
171
187
@@ -175,12 +191,16 @@ def on_success(self, datasets):
175
191
list of DatasetRefs
176
192
"""
177
193
for dataset in datasets :
194
+ await asyncio .sleep (0 )
178
195
LOGGER .info ("file %s successfully ingested" , dataset .path .ospath )
179
196
image_data = ImageData (dataset )
180
197
LOGGER .debug ("image_data.get_info() = %s" , image_data .get_info ())
181
- self .transmit_status (image_data .get_info (), code = 0 , description = "file ingested" )
198
+ await self .transmit_status (image_data .get_info (), code = 0 , description = "file ingested" )
182
199
183
200
def on_ingest_failure (self , exposures , exc ):
201
+ asyncio .create_task (self ._on_ingest_failure (exposures , exc ))
202
+
203
+ async def _on_ingest_failure (self , exposures , exc ):
184
204
"""Callback used on ingest failure. Used to transmit
185
205
unsuccessful data ingestion status
186
206
@@ -193,11 +213,12 @@ def on_ingest_failure(self, exposures, exc):
193
213
194
214
"""
195
215
for f in exposures .files :
216
+ await asyncio .sleep (0 )
196
217
real_file = f .filename .ospath
197
218
self .move_file_to_bad_dir (real_file )
198
219
cause = self .extract_cause (exc )
199
220
info = self .rawexposure_info (f )
200
- self .transmit_status (info , code = 1 , description = f"ingest failure: { cause } " )
221
+ await self .transmit_status (info , code = 1 , description = f"ingest failure: { cause } " )
201
222
202
223
def on_metadata_failure (self , filename , exc ):
203
224
"""Callback used on metadata extraction failure. Used to transmit
@@ -215,7 +236,7 @@ def on_metadata_failure(self, filename, exc):
215
236
216
237
cause = self .extract_cause (exc )
217
238
info = self .undef_metadata (real_file )
218
- self .transmit_status (info , code = 2 , description = f"metadata failure: { cause } " )
239
+ asyncio . create_task ( self .transmit_status (info , code = 2 , description = f"metadata failure: { cause } " ) )
219
240
220
241
def move_file_to_bad_dir (self , filename ):
221
242
bad_dir = self .create_bad_dirname (self .bad_file_dir , self .staging_dir , filename )
@@ -234,6 +255,7 @@ async def ingest(self, file_list):
234
255
"""
235
256
236
257
# Ingest image.
258
+ await asyncio .sleep (0 )
237
259
self .task .run (file_list )
238
260
239
261
def getName (self ):
@@ -251,7 +273,7 @@ async def clean_task(self):
251
273
seconds = TimeInterval .calculateTotalSeconds (self .scanInterval )
252
274
while True :
253
275
if self .csc :
254
- self .csc .log .info ("butler repo cleaning started" )
276
+ self .csc .log .info ("calling butler repo clean started" )
255
277
256
278
await self .clean ()
257
279
@@ -264,6 +286,7 @@ async def clean(self):
264
286
were ingested before the configured Interval
265
287
"""
266
288
289
+ await asyncio .sleep (0 )
267
290
# calculate the time value which is Time.now - the
268
291
# "olderThan" configuration
269
292
t = Time .now ()
@@ -273,10 +296,15 @@ async def clean(self):
273
296
)
274
297
t = t - td
275
298
299
+ LOGGER .info ("about to createButler()" )
276
300
butler = self .createButler ()
301
+ await asyncio .sleep (0 )
277
302
303
+ LOGGER .info ("about to refresh()" )
278
304
butler .registry .refresh ()
305
+ await asyncio .sleep (0 )
279
306
307
+ LOGGER .info ("about to run queryDatasets" )
280
308
# get all datasets in these collections
281
309
allCollections = self .collections if self .cleanCollections is None else self .cleanCollections
282
310
all_datasets = set (
@@ -287,21 +315,29 @@ async def clean(self):
287
315
bind = {"ref_date" : t },
288
316
)
289
317
)
318
+ LOGGER .info ("done running queryDatasets" )
290
319
await asyncio .sleep (0 )
291
320
321
+ LOGGER .info ("about to run queryCollections" )
292
322
# get all TAGGED collections
293
323
tagged_cols = list (butler .registry .queryCollections (collectionTypes = CollectionType .TAGGED ))
324
+ LOGGER .info ("done running queryCollections" )
294
325
295
326
await asyncio .sleep (0 )
296
327
# Note: The code below is to get around an issue where passing
297
328
# an empty list as the collections argument to queryDatasets
298
329
# returns all datasets.
299
330
if tagged_cols :
300
331
# get all TAGGED datasets
332
+ LOGGER .info ("about to run queryDatasets for TAGGED collections" )
301
333
tagged_datasets = set (butler .registry .queryDatasets (datasetType = ..., collections = tagged_cols ))
334
+ LOGGER .info ("done running queryDatasets for TAGGED collections; differencing datasets" )
335
+ await asyncio .sleep (0 )
302
336
303
337
# get a set of datasets in all_datasets, but not in tagged_datasets
304
338
ref = all_datasets .difference (tagged_datasets )
339
+ LOGGER .info ("done differencing datasets" )
340
+ await asyncio .sleep (0 )
305
341
else :
306
342
# no TAGGED collections, so use all_datasets
307
343
ref = all_datasets
@@ -329,4 +365,6 @@ async def clean(self):
329
365
LOGGER .info ("error removing %s: %s" , uri , e )
330
366
331
367
await asyncio .sleep (0 )
368
+ LOGGER .info ("about to run pruneDatasets" )
332
369
butler .pruneDatasets (ref , purge = True , unstore = True )
370
+ LOGGER .info ("done running pruneDatasets" )
0 commit comments