Skip to content

Commit cd40e04

Browse files
committed
fix(core): update alive seconds calculation and log initial alive seconds to Metric
1 parent f591baf commit cd40e04

File tree

1 file changed

+16
-1
lines changed
  • src/server/core/acontext_core/service/data

1 file changed

+16
-1
lines changed

src/server/core/acontext_core/service/data/sandbox.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ async def _update_will_total_alive_seconds(
2424
) -> None:
2525
"""
2626
Update the will_total_alive_seconds field based on how long the sandbox has been alive.
27-
Formula: DEFAULT_KEEPALIVE_SECONDS + (current_time - created_at)
27+
Formula: reset_alive_seconds + (current_time - created_at)
28+
29+
Args:
30+
db_session: Database session.
31+
sandbox_id: The sandbox ID.
32+
reset_alive_seconds: The seconds to extend from current time (default: DEFAULT_KEEPALIVE_SECONDS).
33+
This is the remaining alive time from now, not a reset value.
2834
"""
2935
sandbox_log = await db_session.get(SandboxLog, sandbox_id)
3036
if not sandbox_log:
@@ -111,6 +117,15 @@ async def create_sandbox(
111117
db_session.add(sandbox_log)
112118
await db_session.flush()
113119

120+
# Record the initial alive seconds to Metric
121+
asyncio.create_task(
122+
capture_increment(
123+
project_id=project_id,
124+
tag=MetricTags.new_sandbox_alive,
125+
increment=DEFAULT_CORE_CONFIG.sandbox_default_keepalive_seconds,
126+
)
127+
)
128+
114129
LOG.debug(
115130
f"Created sandbox {sandbox_log.id} -> backend {backend.type}:{info.sandbox_id}"
116131
)

0 commit comments

Comments
 (0)