Skip to content

Commit 70d3c9e

Browse files
committed
fix logging + add synced_commit to healthcheck
1 parent ec47a3b commit 70d3c9e

File tree

6 files changed

+25
-9
lines changed

6 files changed

+25
-9
lines changed

src/codegen/cli/commands/run/run_daemon.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def run_daemon(session: CodegenSession, function, diff_preview: int | None = Non
2222
with create_spinner(f"Running {function.name}...") as status:
2323
try:
2424
client = _get_docker_client(session)
25-
run_output = client.run_function(function)
25+
run_output = client.run_function(function, commit=not diff_preview)
2626
rich.print(f"✅ Ran {function.name} successfully")
2727

2828
if run_output.logs:
@@ -54,10 +54,11 @@ def run_daemon(session: CodegenSession, function, diff_preview: int | None = Non
5454
rich.print("")
5555
rich.print("[yellow] No changes were produced by this codemod[/yellow]")
5656

57-
rich.print("[green]✓ Changes have been applied to your local filesystem[/green]")
58-
rich.print("[yellow]→ Don't forget to commit your changes:[/yellow]")
59-
rich.print(format_command("git add ."))
60-
rich.print(format_command("git commit -m 'Applied codemod changes'"))
57+
if diff_preview:
58+
rich.print("[green]✓ Changes have been applied to your local filesystem[/green]")
59+
rich.print("[yellow]→ Don't forget to commit your changes:[/yellow]")
60+
rich.print(format_command("git add ."))
61+
rich.print(format_command("git commit -m 'Applied codemod changes'"))
6162

6263
except ServerError as e:
6364
status.stop()

src/codegen/cli/commands/start/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def start_command(port: int | None, platform: str, detached: bool = False, skip_
2929
repo_config = RepoConfig.from_repo_path(str(repo_path))
3030
if (container := DockerContainer.get(repo_config.name)) is not None:
3131
if force:
32+
rich.print(f"[yellow]Removing existing runner {repo_config.name} to force restart[/yellow]")
3233
container.remove()
3334
else:
3435
return _handle_existing_container(repo_config, container, force)
@@ -100,6 +101,7 @@ def _run_docker_container(repo_config: RepoConfig, port: int, detached: bool) ->
100101
"REPOSITORY_OWNER": LocalGitRepo(repo_config.repo_path).owner,
101102
"REPOSITORY_PATH": container_repo_path,
102103
"GITHUB_TOKEN": SecretsConfig().github_token,
104+
"PYTHONUNBUFFERED": "1", # Ensure Python output is unbuffered
103105
}
104106
envvars_args = [arg for k, v in envvars.items() for arg in ("--env", f"{k}={v}")]
105107
mount_args = ["-v", f"{repo_config.repo_path}:{container_repo_path}"]
@@ -110,3 +112,7 @@ def _run_docker_container(repo_config: RepoConfig, port: int, detached: bool) ->
110112

111113
rich.print(f"run_cmd: {str.join(' ', run_cmd)}")
112114
subprocess.run(run_cmd, check=True)
115+
116+
if detached:
117+
rich.print("[yellow]Container started in detached mode. To view logs, run:[/yellow]")
118+
rich.print(f"[bold]docker logs -f {repo_config.name}[/bold]")

src/codegen/runner/clients/docker_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def __init__(self, container: DockerContainer):
1717
raise Exception(msg)
1818
super().__init__(container.host, container.port)
1919

20-
def run_function(self, function: DecoratedFunction) -> CodemodRunResult:
21-
req = RunFunctionRequest(function_name=function.name, codemod_source=function.source, commit=True)
20+
def run_function(self, function: DecoratedFunction, commit: bool) -> CodemodRunResult:
21+
req = RunFunctionRequest(function_name=function.name, codemod_source=function.source, commit=commit)
2222
response = self.post(RUN_FUNCTION_ENDPOINT, req.model_dump())
2323
return CodemodRunResult.model_validate(response.json())
2424

src/codegen/runner/models/apis.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
class ServerInfo(BaseModel):
2121
repo_name: str | None = None
22+
synced_commit: str | None = None
2223
warmup_state: WarmupState = WarmupState.PENDING
2324

2425

src/codegen/runner/sandbox/server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ async def lifespan(server: FastAPI):
4545
runner = SandboxRunner(repo_config=repo_config)
4646
server_info.warmup_state = WarmupState.PENDING
4747
await runner.warmup()
48+
server_info.synced_commit = runner.commit.hexsha
4849
server_info.warmup_state = WarmupState.COMPLETED
4950
except Exception:
5051
logger.exception("Failed to build graph during warmup")

src/codegen/runner/servers/local_daemon.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
from codegen.runner.sandbox.runner import SandboxRunner
1818
from codegen.shared.enums.programming_language import ProgrammingLanguage
1919

20+
logging.basicConfig(
21+
level=logging.INFO,
22+
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
23+
force=True,
24+
)
25+
2026
logger = logging.getLogger(__name__)
2127

2228
server_info: ServerInfo
@@ -42,14 +48,15 @@ async def lifespan(server: FastAPI):
4248
runner = SandboxRunner(repo_config=repo_config)
4349
server_info.warmup_state = WarmupState.PENDING
4450
await runner.warmup()
51+
server_info.synced_commit = runner.commit.hexsha
4552
server_info.warmup_state = WarmupState.COMPLETED
4653
except Exception:
4754
logger.exception("Failed to build graph during warmup")
4855
server_info.warmup_state = WarmupState.FAILED
4956

50-
logger.info("Sandbox fastapi server is ready to accept requests")
57+
logger.info("Local daemon is ready to accept requests!")
5158
yield
52-
logger.info("Shutting down sandbox fastapi server")
59+
logger.info("Shutting down local daemon server")
5360

5461

5562
app = FastAPI(lifespan=lifespan)

0 commit comments

Comments
 (0)