Skip to content

Commit

Permalink
Restructuring to handle DB locks
Browse files Browse the repository at this point in the history
  • Loading branch information
KastanDay committed Apr 1, 2024
1 parent b6b525f commit 11cb80d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions ai_ta_backend/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,20 @@ def main_flow(self, name: str, api_key: str = "", data: str = ""):
raise Exception('No executions found')
id = str(id)

# start job
try:
self.supabase_client.table('n8n_api_keys').insert({"id": id}).execute()
start_time = time.monotonic()
self.supabase_client.table('n8n_api_keys').insert({"in_progress_workflow_id": id}).execute()
self.execute_flow(hook, new_data)
print("Executed")
print(f"⏰ Runtime to execute_flow(): {(time.monotonic() - start_time):.4f} seconds")
except:
pass
finally:
# TODO: Remove lock from Supabase table.
pass

try:
executions = self.get_executions(20, id, True, api_key)
print("Got executions", executions)
while executions is None:
Expand All @@ -220,10 +230,11 @@ def main_flow(self, name: str, api_key: str = "", data: str = ""):
print("Can't find id in executions")
time.sleep(1)
print("Found id in executions ")
self.supabase_client.table('n8n_api_keys').delete().eq('id', id).execute()
self.supabase_client.table('n8n_api_keys').delete().eq('in_progress_workflow_id', id).execute()
print("Deleted id")
print("Returning")
except Exception as e:
self.supabase_client.table('n8n_api_keys').delete().eq('id', id).execute()
self.supabase_client.table('n8n_api_keys').delete().eq('in_progress_workflow_id', id).execute()
return {"error": str(e)}

return executions

0 comments on commit 11cb80d

Please sign in to comment.