mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-24 16:23:11 +00:00
Fix process hanging after restart
This commit is contained in:
parent
dff1ca961f
commit
919f46b2e1
@ -7,6 +7,7 @@ import pkg/ethers
|
||||
import pkg/libp2p
|
||||
import std/os
|
||||
import std/strutils
|
||||
import std/times
|
||||
import codex/conf
|
||||
import ./codexclient
|
||||
import ./nodeprocess
|
||||
@ -78,6 +79,9 @@ proc apiUrl*(node: CodexProcess): string {.raises: [CodexProcessError].} =
|
||||
let config = node.config
|
||||
return "http://" & config.apiBindAddress & ":" & $config.apiPort & "/api/codex/v1"
|
||||
|
||||
proc logFile*(node: CodexProcess): ?string {.raises: [CodexProcessError].} =
|
||||
node.config.logFile
|
||||
|
||||
proc client*(node: CodexProcess): CodexClient {.raises: [CodexProcessError].} =
|
||||
if client =? node.client:
|
||||
return client
|
||||
@ -85,6 +89,25 @@ proc client*(node: CodexProcess): CodexClient {.raises: [CodexProcessError].} =
|
||||
node.client = some client
|
||||
return client
|
||||
|
||||
proc updateLogFile(node: CodexProcess, newLogFile: string) =
|
||||
for arg in node.arguments.mitems:
|
||||
if arg.startsWith("--log-file="):
|
||||
arg = "--log-file=" & newLogFile
|
||||
break
|
||||
|
||||
method restart*(node: CodexProcess) {.async.} =
|
||||
trace "restarting codex"
|
||||
await node.stop()
|
||||
if logFile =? node.logFile:
|
||||
# chronicles truncates the existing log file on start, so changed the log
|
||||
# file cli param to create a new one
|
||||
node.updateLogFile(
|
||||
logFile & "_restartedAt_" & now().format("yyyy-MM-dd'_'HH-mm-ss") & ".log"
|
||||
)
|
||||
await node.start()
|
||||
await node.waitUntilStarted()
|
||||
trace "codex process restarted"
|
||||
|
||||
method stop*(node: CodexProcess) {.async: (raises: []).} =
|
||||
logScope:
|
||||
nodeName = node.name
|
||||
|
||||
@ -137,13 +137,10 @@ method stop*(
|
||||
error = e.msg
|
||||
writeStackTrace()
|
||||
finally:
|
||||
proc closeProcessStreams() {.async: (raises: []).} =
|
||||
trace "closing node process' streams"
|
||||
await node.process.closeWait()
|
||||
node.process = nil
|
||||
trace "node process' streams closed"
|
||||
|
||||
asyncSpawn closeProcessStreams()
|
||||
trace "closing node process' streams"
|
||||
await node.process.closeWait()
|
||||
node.process = nil
|
||||
trace "node process' streams closed"
|
||||
|
||||
proc waitUntilOutput*(
|
||||
node: NodeProcess, output: string
|
||||
@ -184,7 +181,7 @@ proc waitUntilStarted*(
|
||||
raise
|
||||
newException(NodeProcessError, "node did not output '" & node.startedOutput & "'")
|
||||
|
||||
proc restart*(node: NodeProcess) {.async.} =
|
||||
method restart*(node: NodeProcess) {.base, async.} =
|
||||
await node.stop()
|
||||
await node.start()
|
||||
await node.waitUntilStarted()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user