From 9f68963f1841c3c44f15edbdee257ba6b983d100 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Sat, 18 Feb 2017 23:09:09 -0600 Subject: [PATCH] WIP: Working on server. --- api.rst | 8 ++++++++ strawboss.nim | 19 +++++++++++++++++-- strawboss.nimble | 2 +- 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 api.rst diff --git a/api.rst b/api.rst new file mode 100644 index 0000000..4dd82a4 --- /dev/null +++ b/api.rst @@ -0,0 +1,8 @@ +GET /api/ping +POST /api/auth-token +GET /api/projects -- return project summaries +POST /api/projects -- create a new project +GET /api/project/ -- return detailed project record (include steps) +GET /api/project// -- return detailed step information (include runs) +POST /api/project///run/ -- kick off a run +GET /api/project///run/ -- return detailed run information diff --git a/strawboss.nim b/strawboss.nim index b9b9a2c..f78bcf8 100644 --- a/strawboss.nim +++ b/strawboss.nim @@ -1,4 +1,8 @@ -import docopt, json, logging, nre, os, osproc, sequtils, streams, strtabs, strutils, tables, tempfile +import asyncdispatch, asyncnet, docopt, jester, json, logging, nre, os, + osproc, sequtils, streams, strtabs, strutils, tables, tempfile + +settings: + port = Port(8180) let SB_VER = "0.1.0" @@ -274,9 +278,18 @@ proc runStep(step: Step, wksp: Workspace): void = raiseEx "step " & step.name & " failed: unable to copy artifact " & artifactPath & ":\n" & getCurrentExceptionMsg() +# Server routes +routes: + get "/api/ping": + resp $(%*"pong"), "application/json" + + get "/api/projects": + resp $(%*[]), "application/json" + when isMainModule: - logging.addHandler(newConsoleLogger()) + if logging.getHandlers().len == 0: + logging.addHandler(newConsoleLogger()) let cfg = loadStrawBossConfig("strawboss.config.json") if not existsDir(cfg.artifactsRepo): @@ -320,3 +333,5 @@ Usage: except: fatal "strawboss: " & getCurrentExceptionMsg() quit(QuitFailure) + elif args["serve"]: + runForever() diff --git a/strawboss.nimble b/strawboss.nimble index 56d480f..7af2d12 100644 --- a/strawboss.nimble +++ b/strawboss.nimble @@ -8,5 +8,5 @@ license = "MIT" # Dependencies -requires @["nim >= 0.16.1", "docopt >= 0.1.0", "tempfile"] +requires @["nim >= 0.16.1", "docopt >= 0.1.0", "tempfile", "jester"]