@@ -123,84 +123,39 @@ async def invoke_tune_upload_handler(
123123 logger .exception (f"Network error during download:{ e } " )
124124 raise
125125
126- if settings .ENVIRONMENT .lower () in ["local" , "crc" ]:
127- tune_dir = os .path .join (settings .TUNE_BASEDIR , f"tune-tasks/{ tune_id } " )
128- if os .path .isdir (tune_dir ) is False :
129- os .mkdir (tune_dir )
126+ tune_dir = os .path .join (settings .TUNE_BASEDIR , f"tune-tasks/{ tune_id } " )
127+ if os .path .isdir (tune_dir ) is False :
128+ os .makedirs (tune_dir , exist_ok = True )
130129
131- tune_config_deploy_bucket_dir = os .path .join (
132- settings .TUNE_BASEDIR , tune_config_deploy_bucket_key
133- )
134- tune_config_bucket_dir = os .path .join (
135- settings .TUNE_BASEDIR , tune_config_bucket_key
136- )
137- tune_checkpoint_bucket_dir = os .path .join (
138- settings .TUNE_BASEDIR , tune_checkpoint_bucket_key
139- )
140-
141- if tune_config_url [0 :4 ] == "http" :
142- with open (tune_config_deploy_bucket_dir , "w" ) as config_file :
143- config_file .write (tune_config_response .text )
144- with open (tune_config_bucket_dir , "w" ) as config_file :
145- config_file .write (tune_config_response .text )
146-
147- elif tune_config_url [0 :4 ] == "file" :
148- if not os .path .exists (tune_config_deploy_bucket_dir ):
149- shutil .copyfile (tune_config_url [7 :], tune_config_deploy_bucket_dir )
150- if not os .path .exists (tune_config_bucket_dir ):
151- shutil .copyfile (tune_config_url [7 :], tune_config_bucket_dir )
152-
153- if tune_checkpoint_url [0 :4 ] == "http" :
154- with open (tune_checkpoint_bucket_dir , "wb" ) as checkpoint_file :
155- checkpoint_file .write (tune_checkpoint_response .content )
156- elif tune_checkpoint_url [0 :4 ] == "file" :
157- if not os .path .exists (tune_checkpoint_bucket_dir ):
158- shutil .copyfile (tune_checkpoint_url [7 :], tune_checkpoint_bucket_dir )
130+ tune_config_deploy_bucket_dir = os .path .join (
131+ settings .TUNE_BASEDIR , tune_config_deploy_bucket_key
132+ )
133+ tune_config_bucket_dir = os .path .join (
134+ settings .TUNE_BASEDIR , tune_config_bucket_key
135+ )
136+ tune_checkpoint_bucket_dir = os .path .join (
137+ settings .TUNE_BASEDIR , tune_checkpoint_bucket_key
138+ )
159139
160- else :
161- pipelines_bucket_name = settings .TUNES_FILES_BUCKET
162- try :
163- logger .info (f"Connect to cos bucket{ pipelines_bucket_name } " )
164- pipeline_s3_client = boto3 .client (
165- "s3" ,
166- aws_access_key_id = settings .OBJECT_STORAGE_KEY_ID ,
167- aws_secret_access_key = settings .OBJECT_STORAGE_SEC_KEY ,
168- endpoint_url = settings .OBJECT_STORAGE_ENDPOINT ,
169- config = Config (
170- signature_version = settings .OBJECT_STORAGE_SIGNATURE_VERSION
171- ),
172- verify = (settings .ENVIRONMENT .lower () not in ["local" , "crc" ]),
173- )
174- except ValueError as exc :
175- logger .error (f"pipeline_s3_client Misconfiguration: { str (exc )} " )
176-
177- try :
178- logger .info ("Uploading tune config file" )
179- # Uploading both config_deploy.yaml and {tune_id}_config.yaml
180- pipeline_s3_client .upload_fileobj (
181- tune_config_response .raw ,
182- Bucket = pipelines_bucket_name ,
183- Key = tune_config_deploy_bucket_key ,
184- )
185- pipeline_s3_client .upload_fileobj (
186- tune_config_response .raw ,
187- Bucket = pipelines_bucket_name ,
188- Key = tune_config_bucket_key ,
189- )
190- logger .info ("Uploading tune config Succeeded" )
140+ if tune_config_url [0 :4 ] == "http" :
141+ with open (tune_config_deploy_bucket_dir , "w" ) as config_file :
142+ config_file .write (tune_config_response .text )
143+ with open (tune_config_bucket_dir , "w" ) as config_file :
144+ config_file .write (tune_config_response .text )
145+
146+ elif tune_config_url [0 :4 ] == "file" :
147+ if not os .path .exists (tune_config_deploy_bucket_dir ):
148+ shutil .copyfile (tune_config_url [7 :], tune_config_deploy_bucket_dir )
149+ if not os .path .exists (tune_config_bucket_dir ):
150+ shutil .copyfile (tune_config_url [7 :], tune_config_bucket_dir )
151+
152+ if tune_checkpoint_url [0 :4 ] == "http" :
153+ with open (tune_checkpoint_bucket_dir , "wb" ) as checkpoint_file :
154+ checkpoint_file .write (tune_checkpoint_response .content )
155+ elif tune_checkpoint_url [0 :4 ] == "file" :
156+ if not os .path .exists (tune_checkpoint_bucket_dir ):
157+ shutil .copyfile (tune_checkpoint_url [7 :], tune_checkpoint_bucket_dir )
191158
192- logger .info ("uploading tune checkpoint file" )
193- pipeline_s3_client .upload_fileobj (
194- tune_checkpoint_response .raw ,
195- Bucket = pipelines_bucket_name ,
196- Key = tune_checkpoint_bucket_key ,
197- )
198- except (requests .exceptions .ConnectionError , requests .exceptions .Timeout ) as e :
199- logger .exception (f"Network error during download:{ e } " )
200- raise
201- except ClientError as e :
202- logger .exception (f"Failed to upload files to cos: { e } " )
203- raise
204159 logger .info ("Updating the tune with {tune_id} status to Finished" )
205160 tunes_crud .update (
206161 db = db ,
0 commit comments