summaryrefslogtreecommitdiff
path: root/src/SomhairlesDream.Frontend/App.fs
diff options
context:
space:
mode:
Diffstat (limited to 'src/SomhairlesDream.Frontend/App.fs')
-rw-r--r--src/SomhairlesDream.Frontend/App.fs91
1 files changed, 49 insertions, 42 deletions
diff --git a/src/SomhairlesDream.Frontend/App.fs b/src/SomhairlesDream.Frontend/App.fs
index e6edd51..0e6bcd4 100644
--- a/src/SomhairlesDream.Frontend/App.fs
+++ b/src/SomhairlesDream.Frontend/App.fs
@@ -707,48 +707,7 @@ let selectionForLiveStart (selection: RunSelection) =
else
selection
-let startRun (selection: RunSelection) =
- let requestBody =
- createObj
- [ "projectId" ==> selection.ProjectId
- "runId" ==> selection.RunId
- "baseId" ==> selection.BaseId
- "targetId" ==> selection.TargetId
- "render" ==> selection.Render ]
-
- let requestOptions =
- createObj
- [ "method" ==> "POST"
- "headers" ==> createObj [ "Content-Type" ==> "application/json" ]
- "body" ==> JS.JSON.stringify requestBody ]
-
- setText "run-message" "正在启动设计运行"
- updateStreamState "实时链路 · 等待服务端确认"
-
- async {
- try
- let! response = fetch ("/api/runs/start", requestOptions) |> Async.AwaitPromise
-
- if response.ok then
- let! value = response.json() |> Async.AwaitPromise
- let payload = value :?> SnapshotPayload
- updateState payload
- connectToServer selection
- updateStreamState "实时链路 · SSE 已连接"
- else
- setText "run-message" (sprintf "启动失败 · HTTP %d" response.status)
- updateStreamState "实时链路 · 启动失败"
- with _ ->
- setText "run-message" "启动失败 · 无法连接服务端"
- updateStreamState "实时链路 · 连接失败"
- }
- |> Async.StartImmediate
-
-/// Boot-time historical load: surface the pre-published probe build replay so
-/// first-time visitors see the real vehicle instead of an empty placeholder.
-/// Any failure leaves the honest placeholder idle state untouched.
-let loadBootHistory () =
- let selection = selectedRun ()
+let loadHistoryFor (selection: RunSelection) =
let projectId = JS.encodeURIComponent selection.ProjectId
let runId = JS.encodeURIComponent selection.RunId
let url = sprintf "/api/artifacts/manifest?projectId=%s&runId=%s" projectId runId
@@ -793,6 +752,54 @@ let loadBootHistory () =
()
}
|> Async.StartImmediate
+let startRun (selection: RunSelection) =
+ let requestBody =
+ createObj
+ [ "projectId" ==> selection.ProjectId
+ "runId" ==> selection.RunId
+ "baseId" ==> selection.BaseId
+ "targetId" ==> selection.TargetId
+ "render" ==> selection.Render ]
+
+ let requestOptions =
+ createObj
+ [ "method" ==> "POST"
+ "headers" ==> createObj [ "Content-Type" ==> "application/json" ]
+ "body" ==> JS.JSON.stringify requestBody ]
+
+ setText "run-message" "正在启动设计运行"
+ updateStreamState "实时链路 · 等待服务端确认"
+
+ async {
+ try
+ let! response = fetch ("/api/runs/start", requestOptions) |> Async.AwaitPromise
+
+ if response.ok then
+ let! value = response.json() |> Async.AwaitPromise
+ let payload = value :?> SnapshotPayload
+ updateState payload
+ connectToServer selection
+ updateStreamState "实时链路 · SSE 已连接"
+ elif response.status = 409 then
+ // The run id already exists on the server. If it completed
+ // earlier, replay its published history instead of treating
+ // the submit as a failure.
+ setText "run-message" "该运行已完成 · 载入历史回放"
+ loadHistoryFor selection
+ else
+ setText "run-message" (sprintf "启动失败 · HTTP %d" response.status)
+ updateStreamState "实时链路 · 启动失败"
+ with _ ->
+ setText "run-message" "启动失败 · 无法连接服务端"
+ updateStreamState "实时链路 · 连接失败"
+ }
+ |> Async.StartImmediate
+
+/// Boot-time historical load: surface the pre-published probe build replay so
+/// first-time visitors see the real vehicle instead of an empty placeholder.
+/// Any failure leaves the honest placeholder idle state untouched.
+let loadBootHistory () =
+ loadHistoryFor (selectedRun ())
let boot () =
showFrameMetadata frames[0]