Reworking runs to include an id, save the run request.

This commit is contained in:
Jonathan Bernard
2017-05-11 10:51:06 -05:00
parent e2c3aeca09
commit 3d8454d486
6 changed files with 75 additions and 20 deletions

View File

@ -1,4 +1,4 @@
import logging, json, os, nre, sequtils, strtabs, tables, times
import logging, json, os, nre, sequtils, strtabs, tables, times, uuids
import private/util
from langutils import sameContents
@ -25,6 +25,7 @@ type
envVars*: StringTableRef
RunRequest* = object
id*: UUID
projectName*, stepName*, buildRef*, workspaceDir*: string
forceRebuild*: bool
@ -67,6 +68,15 @@ proc `==`*(a, b: StrawBossConfig): bool =
sameContents(a.users, b.users) and
sameContents(a.projects, b.projects)
proc `==`*(a, b: RunRequest): bool =
result =
a.id == b.id and
a.projectName == b.projectName and
a.stepName == b.stepName and
a.buildRef == b.buildRef and
a.workspaceDir == b.workspaceDir and
a.forceRebuild == b.forceRebuild
# Util methods on custom types
proc findProject*(cfg: StrawBossConfig, projectName: string): ProjectDef =
let candidates = cfg.projects.filterIt(it.name == projectName)
@ -182,12 +192,9 @@ proc loadBuildStatus*(statusFile: string): BuildStatus =
state: jsonObj.getOrFail("state", "build status").getStr,
details: jsonObj.getIfExists("details").getStr("") )
# TODO: unused and untested, add tests if we start using this
proc parseRunRequest*(reqStr: string): RunRequest =
let reqJson = parseJson(reqStr)
proc parseRunRequest*(reqJson: JsonNode): RunRequest =
result = RunRequest(
id: parseUUID(reqJson.getOrFail("id", "RunRequest").getStr),
projectName: reqJson.getOrFail("projectName", "RunRequest").getStr,
stepName: reqJson.getOrFail("stepName", "RunRequest").getStr,
buildRef: reqJson.getOrFail("buildRef", "RunRequest").getStr,
@ -213,6 +220,7 @@ proc `%`*(p: ProjectDef): JsonNode =
proc `%`*(req: RunRequest): JsonNode =
result = %* {
"id": $req.id,
"projectName": req.projectName,
"stepName": req.stepName,
"buildRef": req.buildRef,