Reworking runs to include an id, save the run request.
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
import algorithm, asyncdispatch, bcrypt, jester, json, jwt, logging, os, osproc,
|
||||
sequtils, strutils, tempfile, times, unittest
|
||||
sequtils, strutils, tempfile, times, unittest, uuids
|
||||
|
||||
import ./configuration, ./core, private/util
|
||||
|
||||
type Worker = object
|
||||
runId*: UUID
|
||||
process*: Process
|
||||
workingDir*: string
|
||||
|
||||
@ -76,10 +77,11 @@ proc spawnWorker(cfg: StrawBossConfig, req: RunRequest): Worker =
|
||||
|
||||
let dir = mkdtemp()
|
||||
var args = @["run", req.projectName, req.stepName, "-r", req.buildRef,
|
||||
"-w", dir, "-c", cfg.filePath]
|
||||
"-w", dir, "-c", cfg.filePath, "-i", req.id]
|
||||
if req.forceRebuild: args.add("-f")
|
||||
debug "Launching worker: " & cfg.pathToExe & " " & args.join(" ")
|
||||
result = Worker(
|
||||
runId: req.id,
|
||||
process: startProcess(cfg.pathToExe, ".", args, loadEnv(), {poUsePath}),
|
||||
workingDir: dir)
|
||||
|
||||
@ -238,7 +240,20 @@ proc start*(cfg: StrawBossConfig): void =
|
||||
## List all runs
|
||||
|
||||
checkAuth(); if not authed: return true
|
||||
|
||||
|
||||
# Make sure we know about that project
|
||||
var project: ProjectDef
|
||||
try: project = cfg.findProject(@"projectName")
|
||||
except: resp(Http404, makeJsonResp(Http404, getCurrentExceptionMsg()), JSON)
|
||||
|
||||
let runsDir = cfg.artifactsRepo & "/" & project.name & "/runs"
|
||||
if not existsDir(runsDir): resp("[]", JSON)
|
||||
|
||||
let runPaths = toSeq(walkFiles(runsDir & "/*.json"))
|
||||
let runRequests = runPaths.mapIt(parseRunRequest(parseFile(it)))
|
||||
|
||||
resp($(%runRequests), JSON)
|
||||
|
||||
# TODO
|
||||
resp(Http501, makeJsonResp(Http501), JSON)
|
||||
|
||||
@ -279,7 +294,8 @@ proc start*(cfg: StrawBossConfig): void =
|
||||
|
||||
checkAuth(); if not authed: return true
|
||||
|
||||
workers.add(spawnWorker(RunRequest(
|
||||
let runRequest = RunRequest(
|
||||
id: genUUID(),
|
||||
projectName: @"projectName",
|
||||
stepName: @"stepName",
|
||||
buildRef: if @"buildRef" != "": @"buildRef" else: nil,
|
||||
|
Reference in New Issue
Block a user