Shageenderan Sapai commited on
Commit
ea9b4e8
·
1 Parent(s): 08467ad

Fix for s3 location

Browse files
app/__pycache__/assistants.cpython-312.pyc CHANGED
Binary files a/app/__pycache__/assistants.cpython-312.pyc and b/app/__pycache__/assistants.cpython-312.pyc differ
 
app/__pycache__/flows.cpython-312.pyc CHANGED
Binary files a/app/__pycache__/flows.cpython-312.pyc and b/app/__pycache__/flows.cpython-312.pyc differ
 
app/__pycache__/main.cpython-312.pyc CHANGED
Binary files a/app/__pycache__/main.cpython-312.pyc and b/app/__pycache__/main.cpython-312.pyc differ
 
app/__pycache__/user.cpython-312.pyc CHANGED
Binary files a/app/__pycache__/user.cpython-312.pyc and b/app/__pycache__/user.cpython-312.pyc differ
 
app/__pycache__/utils.cpython-312.pyc CHANGED
Binary files a/app/__pycache__/utils.cpython-312.pyc and b/app/__pycache__/utils.cpython-312.pyc differ
 
app/cache.py CHANGED
@@ -32,7 +32,7 @@ def upload_file_to_s3(filename):
32
  s3_client = session.client('s3')
33
  with open(filename, "rb") as f:
34
  ## Upload to Production Folder
35
- s3_client.upload_fileobj(f, bucket, f'dev/users/{user_id}.pkl')
36
  logger.info(f"File {filename} uploaded successfully to S3", extra={'user_id': user_id, 'endpoint': function_name})
37
 
38
  os.remove(filename)
 
32
  s3_client = session.client('s3')
33
  with open(filename, "rb") as f:
34
  ## Upload to Production Folder
35
+ s3_client.upload_fileobj(f, bucket, f'staging/users/{user_id}.pkl')
36
  logger.info(f"File {filename} uploaded successfully to S3", extra={'user_id': user_id, 'endpoint': function_name})
37
 
38
  os.remove(filename)
app/main.py CHANGED
@@ -359,7 +359,7 @@ def migrate_user(request: CreateUserItem, api_key: str = Security(get_api_key)):
359
  def download_file_from_s3(filename, bucket):
360
  user_id = filename.split('.')[0]
361
  function_name = download_file_from_s3.__name__
362
- logger.info(f"Downloading file {filename} from [dev] S3 bucket {bucket}", extra={'user_id': user_id, 'endpoint': function_name})
363
  file_path = os.path.join('users', 'data', filename)
364
  try:
365
  if (AWS_ACCESS_KEY and AWS_SECRET_KEY):
@@ -368,8 +368,8 @@ def migrate_user(request: CreateUserItem, api_key: str = Security(get_api_key)):
368
  session = boto3.session.Session()
369
  s3_client = session.client('s3')
370
  with open(file_path, 'wb') as f:
371
- ## Upload to dev Folder
372
- s3_client.download_fileobj(bucket, f"dev/users/{filename}", f)
373
  logger.info(f"File {filename} downloaded successfully from S3", extra={'user_id': user_id, 'endpoint': function_name})
374
  return True
375
  except Exception as e:
@@ -590,10 +590,10 @@ def create_user(request: CreateUserItem, api_key: str = Security(get_api_key)):
590
  client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
591
 
592
  # check if user exists by looking for pickle file in users/data
593
- if os.path.exists(f'users/data/{request.user_id}.pkl'):
594
- print_log("INFO",f"User already exists: {request.user_id}", extra={"user_id": request.user_id, "endpoint": "/create_user"})
595
- logger.info(f"User already exists: {request.user_id}", extra={"user_id": request.user_id, "endpoint": "/create_user"})
596
- return {"message": f"[OK] User already exists: {request.user_id}"}
597
 
598
  user_info, _ = get_user_info(request.user_id)
599
  if not user_info:
 
359
  def download_file_from_s3(filename, bucket):
360
  user_id = filename.split('.')[0]
361
  function_name = download_file_from_s3.__name__
362
+ logger.info(f"Downloading file {filename} from [staging] S3 bucket {bucket}", extra={'user_id': user_id, 'endpoint': function_name})
363
  file_path = os.path.join('users', 'data', filename)
364
  try:
365
  if (AWS_ACCESS_KEY and AWS_SECRET_KEY):
 
368
  session = boto3.session.Session()
369
  s3_client = session.client('s3')
370
  with open(file_path, 'wb') as f:
371
+ ## Upload to staging Folder
372
+ s3_client.download_fileobj(bucket, f"staging/users/{filename}", f)
373
  logger.info(f"File {filename} downloaded successfully from S3", extra={'user_id': user_id, 'endpoint': function_name})
374
  return True
375
  except Exception as e:
 
590
  client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
591
 
592
  # check if user exists by looking for pickle file in users/data
593
+ # if os.path.exists(f'users/data/{request.user_id}.pkl'):
594
+ # print_log("INFO",f"User already exists: {request.user_id}", extra={"user_id": request.user_id, "endpoint": "/create_user"})
595
+ # logger.info(f"User already exists: {request.user_id}", extra={"user_id": request.user_id, "endpoint": "/create_user"})
596
+ # return {"message": f"[OK] User already exists: {request.user_id}"}
597
 
598
  user_info, _ = get_user_info(request.user_id)
599
  if not user_info:
app/utils.py CHANGED
@@ -1224,7 +1224,7 @@ def download_file_from_s3(filename, bucket):
1224
  s3_client = session.client('s3')
1225
  with open(file_path, 'wb') as f:
1226
  ## Upload to Production Folder
1227
- s3_client.download_fileobj(bucket, f"dev/users/{filename}", f)
1228
  logger.info(f"File {filename} downloaded successfully from S3", extra={'user_id': user_id, 'endpoint': function_name})
1229
  return True
1230
  except Exception as e:
 
1224
  s3_client = session.client('s3')
1225
  with open(file_path, 'wb') as f:
1226
  ## Upload to Production Folder
1227
+ s3_client.download_fileobj(bucket, f"staging/users/{filename}", f)
1228
  logger.info(f"File {filename} downloaded successfully from S3", extra={'user_id': user_id, 'endpoint': function_name})
1229
  return True
1230
  except Exception as e: