|
1 | 1 | import boto3 |
| 2 | +import botocore |
2 | 3 | import json |
3 | 4 | import logging |
4 | 5 | import os |
@@ -190,8 +191,14 @@ def runCellProfiler(message): |
190 | 191 | subfolders = '/'.join((csv_insubfolders)[:-1]) |
191 | 192 | if not os.path.exists(os.path.join(localIn,subfolders)): |
192 | 193 | os.makedirs(os.path.join(localIn,subfolders), exist_ok=True) |
193 | | - s3 = boto3.resource('s3') |
194 | | - s3.meta.client.download_file(WORKSPACE_BUCKET, message['data_file'], data_file_path) |
| 194 | + s3client=boto3.client('s3') |
| 195 | + try: |
| 196 | + s3client.download_file(WORKSPACE_BUCKET, message['data_file'], data_file_path) |
| 197 | + except botocore.exceptions.ClientError: |
| 198 | + printandlog(f"Can't find load data file in S3. Looking for {message['data_file']} in {WORKSPACE_BUCKET}",logger) |
| 199 | + printandlog("Aborting. Can't run without load data.",logger) |
| 200 | + logger.removeHandler(watchtowerlogger) |
| 201 | + return 'DOWNLOAD_PROBLEM' |
195 | 202 | if message['data_file'][-4:]=='.csv': |
196 | 203 | printandlog('Figuring which files to download', logger) |
197 | 204 | import pandas |
@@ -226,8 +233,11 @@ def runCellProfiler(message): |
226 | 233 | os.makedirs(os.path.split(new_file_name)[0]) |
227 | 234 | printandlog(f'Made directory {os.path.split(new_file_name)[0]}',logger) |
228 | 235 | if not os.path.exists(new_file_name): |
229 | | - s3.meta.client.download_file(SOURCE_BUCKET,prefix_on_bucket,new_file_name) |
230 | | - downloaded_files.append(new_file_name) |
| 236 | + try: |
| 237 | + s3client.download_file(SOURCE_BUCKET,prefix_on_bucket,new_file_name) |
| 238 | + downloaded_files.append(new_file_name) |
| 239 | + except botocore.exceptions.ClientError: |
| 240 | + printandlog(f"Can't find file in S3. Looking for {prefix_on_bucket} in {SOURCE_BUCKET}",logger) |
231 | 241 | printandlog(f'Downloaded {str(len(downloaded_files))} files',logger) |
232 | 242 | import random |
233 | 243 | newtag = False |
@@ -255,15 +265,25 @@ def runCellProfiler(message): |
255 | 265 | os.makedirs(os.path.split(new_file_name)[0]) |
256 | 266 | printandlog(f'made directory {os.path.split(new_file_name)[0]}',logger) |
257 | 267 | if not os.path.exists(new_file_name): |
258 | | - s3.meta.client.download_file(SOURCE_BUCKET,prefix_on_bucket,new_file_name) |
259 | | - downloaded_files.append(new_file_name) |
| 268 | + try: |
| 269 | + s3client.download_file(SOURCE_BUCKET,prefix_on_bucket,new_file_name) |
| 270 | + downloaded_files.append(new_file_name) |
| 271 | + except botocore.exceptions.ClientError: |
| 272 | + printandlog(f"Can't find file in S3. Looking for {prefix_on_bucket} in {SOURCE_BUCKET}",logger) |
260 | 273 | printandlog(f'Downloaded {str(len(downloaded_files))} files',logger) |
261 | 274 | else: |
262 | 275 | printandlog("Couldn't parse data file for file download. Not supported input of .csv or .txt",logger) |
263 | 276 | # Download pipeline and update pipeline path in message |
264 | 277 | printandlog(f"Downloading {message['pipeline']} from {WORKSPACE_BUCKET}", logger) |
265 | 278 | pipepath = os.path.join(localIn, message['pipeline'].split('/')[-1]) |
266 | | - s3.meta.client.download_file(WORKSPACE_BUCKET, message['pipeline'], pipepath) |
| 279 | + try: |
| 280 | + s3client.download_file(WORKSPACE_BUCKET, message['pipeline'], pipepath) |
| 281 | + except botocore.exceptions.ClientError: |
| 282 | + printandlog(f"Can't find pipeline in S3. Looking for {message['pipeline']} in {WORKSPACE_BUCKET}",logger) |
| 283 | + printandlog("Aborting. Can't run without pipeline.",logger) |
| 284 | + logger.removeHandler(watchtowerlogger) |
| 285 | + return 'DOWNLOAD_PROBLEM' |
| 286 | + |
267 | 287 | else: |
268 | 288 | data_file_path = os.path.join(DATA_ROOT,message['data_file']) |
269 | 289 | pipepath = os.path.join(DATA_ROOT,message["pipeline"]) |
|
0 commit comments