Fix bug around spawning worker processes.

We were expecting to find the path to the `strawboss` binary implicitly from
the environment, which meant that configuration was also implicit, and required
more setup. Now the path to the binary is explicit in the StrawBoss runtime
configuration, and the path to the configuration file can also be explicitly given.
This commit is contained in:
Jonathan Bernard committed 2017-05-11 10:43:55 -05:00
1 parent 42f37a21e6
commit a1100f17d8
6 files changed
+47 -15

No files matched your search

+19 -4
View File
@@ -77,12 +77,16 @@ proc extractSession(cfg: StrawBossConfig, request: Request): Session =
result = fromJWT(cfg, headerVal[7..^1])
proc spawnWorker(req: RunRequest): Worker =
proc spawnWorker(cfg: StrawBossConfig, req: RunRequest): Worker =
## Kick off a new worker process with the given run information
let dir = mkdtemp()
var args = @["run", req.projectName, req.stepName, "-r", req.buildRef, "-w", dir]
var args = @["run", req.projectName, req.stepName, "-r", req.buildRef,
"-w", dir, "-c", cfg.filePath]
if req.forceRebuild: args.add("-f")
debug "Launching worker: " & cfg.pathToExe & " " & args.join(" ")
result = Worker(
process: startProcess("strawboss", ".", args, loadEnv(), {poUsePath}),
process: startProcess(cfg.pathToExe, ".", args, loadEnv(), {poUsePath}),
workingDir: dir)
proc hashPwd*(pwd: string, cost: int8): string =
@@ -248,7 +252,18 @@ proc start*(cfg: StrawBossConfig): void =
projectName: @"projectName",
stepName: @"stepName",
buildRef: if @"buildRef" != "": @"buildRef" else: nil,
forceRebuild: false))) # TODO support this with optional query params
forceRebuild: false) # TODO support this with optional query params
# TODO: instead of immediately spawning a worker, add the request to a
# queue to be picked up by a worker. Allows capping the number of worker
# prcesses, distributing, etc.
let worker = spawnWorker(cfg, runRequest)
workers.add(worker)
resp($(%*{
"runRequest": runRequest,
"status": { "state": "accepted", "details": "Run request has been queued." }
}))
post "/service/debug/stop":
if not cfg.debug: resp(Http404, makeJsonResp(Http404), JSON)