Web dashboard, task release, logs api

This commit is contained in:
simon987
2019-01-21 20:16:30 -05:00
parent 0346dd8b6b
commit cbd32daf02
65 changed files with 13430 additions and 114 deletions

View File

@@ -15,6 +15,17 @@ type CreateTaskRequest struct {
Priority int64 `json:"priority"`
}
type ReleaseTaskRequest struct {
TaskId int64 `json:"task_id"`
Success bool `json:"success"`
WorkerId *uuid.UUID `json:"worker_id"`
}
type ReleaseTaskResponse struct {
Ok bool `json:"ok"`
Message string `json:"message,omitempty"`
}
type CreateTaskResponse struct {
Ok bool `json:"ok"`
Message string `json:"message,omitempty"`
@@ -137,3 +148,33 @@ func (api WebAPI) workerFromQueryArgs(r *Request) (*storage.Worker, error) {
return worker, nil
}
func (api *WebAPI) TaskRelease(r *Request) {
req := ReleaseTaskRequest{}
if r.GetJson(req) {
res := api.Database.ReleaseTask(req.TaskId, req.WorkerId, req.Success)
response := ReleaseTaskResponse{
Ok: res,
}
if !res {
response.Message = "Could not find a task with the specified Id assigned to this workerId"
logrus.WithFields(logrus.Fields{
"releaseTaskRequest": req,
"taskUpdated": res,
}).Warn("Release task: NOT FOUND")
} else {
logrus.WithFields(logrus.Fields{
"releaseTaskRequest": req,
"taskUpdated": res,
}).Trace("Release task")
}
r.OkJson(response)
}
}