feat: replace synchronous HTTP calls with async client and add background task tracking
This commit is contained in:
+50
-4
@@ -1,4 +1,6 @@
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import time
|
||||
|
||||
from pr.commands.multiplexer_commands import MULTIPLEXER_COMMANDS
|
||||
@@ -40,7 +42,18 @@ def handle_command(assistant, command):
|
||||
if prompt_text.strip():
|
||||
from pr.core.assistant import process_message
|
||||
|
||||
process_message(assistant, prompt_text)
|
||||
task = asyncio.create_task(process_message(assistant, prompt_text))
|
||||
assistant.background_tasks.add(task)
|
||||
task.add_done_callback(
|
||||
lambda t: (
|
||||
assistant.background_tasks.discard(t),
|
||||
(
|
||||
logging.error(f"Background task failed: {t.exception()}")
|
||||
if t.exception()
|
||||
else assistant.background_tasks.discard(t)
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
elif cmd == "/auto":
|
||||
if len(command_parts) < 2:
|
||||
@@ -201,7 +214,18 @@ def review_file(assistant, filename):
|
||||
message = f"Please review this file and provide feedback:\n\n{result['content']}"
|
||||
from pr.core.assistant import process_message
|
||||
|
||||
process_message(assistant, message)
|
||||
task = asyncio.create_task(process_message(assistant, message))
|
||||
assistant.background_tasks.add(task)
|
||||
task.add_done_callback(
|
||||
lambda t: (
|
||||
assistant.background_tasks.discard(t),
|
||||
(
|
||||
logging.error(f"Background task failed: {t.exception()}")
|
||||
if t.exception()
|
||||
else assistant.background_tasks.discard(t)
|
||||
),
|
||||
)
|
||||
)
|
||||
else:
|
||||
print(f"{Colors.RED}Error reading file: {result['error']}{Colors.RESET}")
|
||||
|
||||
@@ -212,7 +236,18 @@ def refactor_file(assistant, filename):
|
||||
message = f"Please refactor this code to improve its quality:\n\n{result['content']}"
|
||||
from pr.core.assistant import process_message
|
||||
|
||||
process_message(assistant, message)
|
||||
task = asyncio.create_task(process_message(assistant, message))
|
||||
assistant.background_tasks.add(task)
|
||||
task.add_done_callback(
|
||||
lambda t: (
|
||||
assistant.background_tasks.discard(t),
|
||||
(
|
||||
logging.error(f"Background task failed: {t.exception()}")
|
||||
if t.exception()
|
||||
else assistant.background_tasks.discard(t)
|
||||
),
|
||||
)
|
||||
)
|
||||
else:
|
||||
print(f"{Colors.RED}Error reading file: {result['error']}{Colors.RESET}")
|
||||
|
||||
@@ -223,7 +258,18 @@ def obfuscate_file(assistant, filename):
|
||||
message = f"Please obfuscate this code:\n\n{result['content']}"
|
||||
from pr.core.assistant import process_message
|
||||
|
||||
process_message(assistant, message)
|
||||
task = asyncio.create_task(process_message(assistant, message))
|
||||
assistant.background_tasks.add(task)
|
||||
task.add_done_callback(
|
||||
lambda t: (
|
||||
assistant.background_tasks.discard(t),
|
||||
(
|
||||
logging.error(f"Background task failed: {t.exception()}")
|
||||
if t.exception()
|
||||
else assistant.background_tasks.discard(t)
|
||||
),
|
||||
)
|
||||
)
|
||||
else:
|
||||
print(f"{Colors.RED}Error reading file: {result['error']}{Colors.RESET}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user