denizparlak1 / learning-platform

1 stars 0 forks source link

s3 delete object sync to async #22

Open denizparlak1 opened 3 weeks ago

denizparlak1 commented 3 weeks ago

The function must change sync to async to prevent lock for multiple users.

denizparlak1 commented 3 weeks ago

def delete_files_by_prefix(self, prefix: str): try: objects_to_delete = self.client.list_objects_v2(Bucket=self.bucket_name, Prefix=prefix) if 'Contents' in objects_to_delete: delete_keys = [{'Key': obj['Key']} for obj in objects_to_delete['Contents']] self.client.delete_objects(Bucket=self.bucket_name, Delete={'Objects': delete_keys}) return True except Exception as e: raise Exception(f"S3 Error during deletion by prefix: {e}")