2626 >>> ingested_record = ingester.upload_file_and_ingest_to_archive(fileobj)
2727
2828"""
29-
3029from ocs_ingester .exceptions import BackoffRetryError , NonFatalDoNotRetryError , DoNotRetryError
3130from ocs_ingester .archive import ArchiveService
3231from ocs_ingester .utils .metrics import upload_and_collect_metrics , get_md5_and_collect_metrics
@@ -160,7 +159,7 @@ def upload_file_to_file_store(fileobj, path=None, file_metadata=None):
160159
161160def ingest_archive_record (version , record , api_root = ingester_settings .API_ROOT ,
162161 auth_token = ingester_settings .AUTH_TOKEN ):
163- """Adds a record to the science archive database.
162+ """Adds a frame record to the science archive database.
164163
165164 Args:
166165 version (dict): Version information returned from the upload to S3
@@ -202,7 +201,8 @@ def ingest_archive_record(version, record, api_root=ingester_settings.API_ROOT,
202201def upload_file_and_ingest_to_archive (fileobj , path = None , file_metadata = None ,
203202 required_headers = archive_settings .REQUIRED_HEADERS ,
204203 blacklist_headers = archive_settings .HEADER_BLACKLIST ,
205- api_root = ingester_settings .API_ROOT , auth_token = ingester_settings .AUTH_TOKEN ):
204+ api_root = ingester_settings .API_ROOT , auth_token = ingester_settings .AUTH_TOKEN ,
205+ is_thumbnail = False , thumbnail_size = None ):
206206 """Uploads a file to S3 and adds the associated record to the science archive database.
207207
208208 This is a standalone function that runs all of the necessary steps to add data to the
@@ -218,6 +218,8 @@ def upload_file_and_ingest_to_archive(fileobj, path=None, file_metadata=None,
218218 auth_token (str): Science archive API authentication token
219219 required_headers (tuple): FITS headers that must be present
220220 blacklist_headers (tuple): FITS headers that should not be ingested
221+ is_thumbnail (bool): Whether the file is a thumbnail
222+ thumbnail_size (str): The size of the thumbnail
221223
222224 Returns:
223225 dict: Information about the uploaded file and record. For example:
@@ -250,6 +252,11 @@ def upload_file_and_ingest_to_archive(fileobj, path=None, file_metadata=None,
250252 try :
251253 if file_metadata is None :
252254 file_metadata = {}
255+ if is_thumbnail :
256+ if thumbnail_size is None :
257+ raise FileSpecificationException ('thumbnail_size must be provided for thumbnail files' )
258+ file_metadata ['size' ] = thumbnail_size
259+ required_headers = archive_settings .REQUIRED_THUMBNAIL_METADATA
253260 open_file = File (fileobj , path )
254261 datafile = FileFactory .get_datafile_class_for_extension (open_file .extension )(
255262 open_file , file_metadata , required_headers = required_headers , blacklist_headers = blacklist_headers
@@ -259,7 +266,7 @@ def upload_file_and_ingest_to_archive(fileobj, path=None, file_metadata=None,
259266 raise DoNotRetryError (str (fe ))
260267
261268 archive = ArchiveService (api_root = api_root , auth_token = auth_token )
262- ingester = Ingester (datafile , filestore , archive )
269+ ingester = Ingester (datafile , filestore , archive , is_thumbnail = is_thumbnail )
263270 return ingester .ingest ()
264271
265272
@@ -269,10 +276,11 @@ class Ingester(object):
269276 A single instance of this class is responsible for parsing a fits file,
270277 uploading the data to s3, and making a call to the archive api.
271278 """
272- def __init__ (self , datafile , filestore , archive ):
279+ def __init__ (self , datafile , filestore , archive , is_thumbnail = False ):
273280 self .datafile = datafile
274281 self .filestore = filestore
275282 self .archive = archive
283+ self .is_thumbnail = is_thumbnail
276284
277285 def ingest (self ):
278286 # Get the Md5 checksum of this file and check if it already exists in the archive
@@ -293,4 +301,5 @@ def ingest(self):
293301 record ['area' ] = self .datafile .get_wcs_corners ()
294302 record ['version_set' ] = [version ]
295303 record ['basename' ] = self .datafile .open_file .basename
296- return self .archive .post_frame (record )
304+
305+ return self .archive .post_thumbnail (record ) if self .is_thumbnail else self .archive .post_frame (record )
0 commit comments