Skip to content

Commit f88cb4f

Browse files
committed
wip
1 parent 8e34b3a commit f88cb4f

File tree

2 files changed

+50
-12
lines changed

2 files changed

+50
-12
lines changed
Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
"""Client used to abstract the weird stdin/stdout communication we have with the sandbox"""
22

33
import logging
4+
import os
5+
import subprocess
46

57
from codegen.git.schemas.repo_config import RepoConfig
68
from codegen.runner.clients.server_client import LocalServerClient
79
from codegen.runner.models.apis import SANDBOX_SERVER_PORT
10+
from codegen.shared.configs.session_configs import config
811

912
logger = logging.getLogger(__name__)
1013

@@ -22,15 +25,50 @@ def __init__(self, repo_config: RepoConfig, git_access_token: str | None, host:
2225
self.git_access_token = git_access_token
2326
super().__init__(server_path=RUNNER_SERVER_PATH, host=host, port=port)
2427

25-
def _get_envs(self):
28+
def _get_envs(self) -> dict:
2629
envs = super()._get_envs()
27-
envs.update(
28-
{
29-
"CODEGEN_REPOSITORY__REPO_PATH": self.repo_config.repo_path,
30-
"CODEGEN_REPOSITORY__REPO_NAME": self.repo_config.name,
31-
"CODEGEN_REPOSITORY__FULL_NAME": self.repo_config.full_name,
32-
"CODEGEN_REPOSITORY__LANGUAGE": self.repo_config.language.value,
33-
"CODEGEN_SECRETS__GITHUB_TOKEN": self.git_access_token,
34-
}
35-
)
30+
codebase_envs = {
31+
"CODEGEN_REPOSITORY__REPO_PATH": self.repo_config.repo_path,
32+
"CODEGEN_REPOSITORY__REPO_NAME": self.repo_config.name,
33+
"CODEGEN_REPOSITORY__FULL_NAME": self.repo_config.full_name,
34+
"CODEGEN_REPOSITORY__LANGUAGE": self.repo_config.language.value,
35+
}
36+
if self.git_access_token is not None:
37+
codebase_envs["CODEGEN_SECRETS__GITHUB_TOKEN"] = self.git_access_token
38+
39+
envs.update(codebase_envs)
3640
return envs
41+
42+
def _start_server(self, server_path: str) -> None:
43+
"""Start the FastAPI server in a subprocess"""
44+
codebase_envs = {
45+
"CODEGEN_REPOSITORY__REPO_PATH": self.repo_config.repo_path,
46+
"CODEGEN_REPOSITORY__REPO_NAME": self.repo_config.name,
47+
"CODEGEN_REPOSITORY__FULL_NAME": self.repo_config.full_name,
48+
"CODEGEN_REPOSITORY__LANGUAGE": self.repo_config.language.value,
49+
}
50+
if self.git_access_token is not None:
51+
codebase_envs["CODEGEN_SECRETS__GITHUB_TOKEN"] = self.git_access_token
52+
53+
envs = os.environ.copy()
54+
envs.update(codebase_envs)
55+
logger.info(f"Starting local server on {self.base_url} with envvars: {envs}")
56+
57+
self._process = subprocess.Popen(
58+
[
59+
"uvicorn",
60+
server_path,
61+
"--host",
62+
self.host,
63+
"--port",
64+
str(self.port),
65+
],
66+
env=envs,
67+
)
68+
self._wait_for_server()
69+
70+
71+
if __name__ == "__main__":
72+
test_config = RepoConfig.from_repo_path("/Users/caroljung/git/codegen/codegen-agi")
73+
client = CodebaseClient(test_config, config.secrets.github_token)
74+
print(client.healthcheck())

src/codegen/runner/clients/server_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __del__(self):
3636
self._process.terminate()
3737
self._process.wait()
3838

39-
def _get_envs(self):
39+
def _get_envs(self) -> dict:
4040
return os.environ.copy()
4141

4242
def _start_server(self, server_path: str) -> None:
@@ -57,7 +57,7 @@ def _start_server(self, server_path: str) -> None:
5757
)
5858
self._wait_for_server()
5959

60-
def _wait_for_server(self, timeout: int = 60, interval: float = 0.1) -> None:
60+
def _wait_for_server(self, timeout: int = 10, interval: float = 0.1) -> None:
6161
"""Wait for the server to start by polling the health endpoint"""
6262
start_time = time.time()
6363
while (time.time() - start_time) < timeout:

0 commit comments

Comments
 (0)