Skip 5-minute duplicate check during CSV import
This commit is contained in:
parent
56ae3f41a4
commit
3c32064c23
2 changed files with 14 additions and 13 deletions
25
crud.py
25
crud.py
|
|
@ -117,19 +117,20 @@ async def authenticate_user(email: str, password: str):
|
|||
return user
|
||||
|
||||
# Agent CRUD operations
|
||||
async def create_agent(agent_data: dict, user_id: str):
|
||||
async def create_agent(agent_data: dict, user_id: str, skip_time_check: bool = False):
|
||||
# Check for duplicate agent names from the same user created recently (within 5 minutes)
|
||||
from datetime import timedelta
|
||||
five_minutes_ago = datetime.utcnow() - timedelta(minutes=5)
|
||||
|
||||
existing_agent = await agents_collection.find_one({
|
||||
"agent_name": agent_data.get("agent_name"),
|
||||
"created_by": user_id,
|
||||
"created_at": {"$gte": five_minutes_ago}
|
||||
})
|
||||
|
||||
if existing_agent:
|
||||
raise ValueError(f"Agent with name '{agent_data.get('agent_name')}' was already created recently. Please wait before creating another agent with the same name.")
|
||||
if not skip_time_check:
|
||||
from datetime import timedelta
|
||||
five_minutes_ago = datetime.utcnow() - timedelta(minutes=5)
|
||||
|
||||
existing_agent = await agents_collection.find_one({
|
||||
"agent_name": agent_data.get("agent_name"),
|
||||
"created_by": user_id,
|
||||
"created_at": {"$gte": five_minutes_ago}
|
||||
})
|
||||
|
||||
if existing_agent:
|
||||
raise ValueError(f"Agent with name '{agent_data.get('agent_name')}' was already created recently. Please wait before creating another agent with the same name.")
|
||||
|
||||
now = datetime.utcnow()
|
||||
agent_doc = {
|
||||
|
|
|
|||
2
main.py
2
main.py
|
|
@ -1131,7 +1131,7 @@ async def import_agents_csv(
|
|||
agent_data["agent_name"] = f"{agent_data['agent_name']} - Imported"
|
||||
|
||||
# Create agent
|
||||
await crud.create_agent(agent_data, user_id)
|
||||
await crud.create_agent(agent_data, user_id, skip_time_check=True)
|
||||
success_count += 1
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue