mirror of
https://github.com/simon987/task_tracker.git
synced 2025-12-10 21:48:52 +00:00
change worker id to serial
This commit is contained in:
@@ -80,7 +80,6 @@ func New() *WebAPI {
|
||||
ctx.SetStatusCode(404)
|
||||
_, _ = fmt.Fprintf(ctx, "Not found")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return api
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"errors"
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/dchest/siphash"
|
||||
"github.com/google/uuid"
|
||||
"src/task_tracker/storage"
|
||||
"strconv"
|
||||
)
|
||||
@@ -114,9 +113,9 @@ func (api *WebAPI) TaskGetFromProject(r *Request) {
|
||||
return
|
||||
}
|
||||
|
||||
project, err := strconv.Atoi(r.Ctx.UserValue("project").(string))
|
||||
project, err := strconv.ParseInt(r.Ctx.UserValue("project").(string), 10, 64)
|
||||
handleErr(err, r)
|
||||
task := api.Database.GetTaskFromProject(worker, int64(project))
|
||||
task := api.Database.GetTaskFromProject(worker, project)
|
||||
|
||||
if task == nil {
|
||||
|
||||
@@ -159,7 +158,7 @@ func (api WebAPI) validateSignature(r *Request) (*storage.Worker, error) {
|
||||
widStr := string(r.Ctx.Request.Header.Peek("X-Worker-Id"))
|
||||
signature := r.Ctx.Request.Header.Peek("X-Signature")
|
||||
|
||||
wid, err := uuid.Parse(widStr)
|
||||
wid, err := strconv.ParseInt(widStr, 10, 64)
|
||||
if err != nil {
|
||||
logrus.WithError(err).WithFields(logrus.Fields{
|
||||
"wid": widStr,
|
||||
@@ -219,7 +218,7 @@ func (api *WebAPI) TaskRelease(r *Request) {
|
||||
var req ReleaseTaskRequest
|
||||
if r.GetJson(&req) {
|
||||
|
||||
res := api.Database.ReleaseTask(req.TaskId, &worker.Id, req.Success)
|
||||
res := api.Database.ReleaseTask(req.TaskId, worker.Id, req.Success)
|
||||
|
||||
response := ReleaseTaskResponse{
|
||||
Ok: res,
|
||||
|
||||
@@ -2,9 +2,9 @@ package api
|
||||
|
||||
import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/google/uuid"
|
||||
"math/rand"
|
||||
"src/task_tracker/storage"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -34,8 +34,8 @@ type GetWorkerResponse struct {
|
||||
}
|
||||
|
||||
type WorkerAccessRequest struct {
|
||||
WorkerId *uuid.UUID `json:"worker_id"`
|
||||
ProjectId int64 `json:"project_id"`
|
||||
WorkerId int64 `json:"worker_id"`
|
||||
ProjectId int64 `json:"project_id"`
|
||||
}
|
||||
|
||||
type WorkerAccessResponse struct {
|
||||
@@ -79,17 +79,27 @@ func (api *WebAPI) WorkerCreate(r *Request) {
|
||||
|
||||
func (api *WebAPI) WorkerGet(r *Request) {
|
||||
|
||||
id, err := uuid.Parse(r.Ctx.UserValue("id").(string))
|
||||
id, err := strconv.ParseInt(r.Ctx.UserValue("id").(string), 10, 64)
|
||||
if err != nil {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
logrus.WithError(err).WithFields(logrus.Fields{
|
||||
"id": id,
|
||||
}).Warn("Invalid UUID")
|
||||
}).Warn("Invalid worker id")
|
||||
|
||||
r.Json(GetWorkerResponse{
|
||||
Ok: false,
|
||||
Message: err.Error(),
|
||||
}, 400)
|
||||
return
|
||||
} else if id <= 0 {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"id": id,
|
||||
}).Warn("Invalid worker id")
|
||||
|
||||
r.Json(GetWorkerResponse{
|
||||
Ok: false,
|
||||
Message: "Invalid worker id",
|
||||
}, 400)
|
||||
return
|
||||
}
|
||||
|
||||
worker := api.Database.GetWorker(id)
|
||||
@@ -188,7 +198,6 @@ func (api *WebAPI) workerCreate(request *CreateWorkerRequest, identity *storage.
|
||||
}
|
||||
|
||||
worker := storage.Worker{
|
||||
Id: uuid.New(),
|
||||
Created: time.Now().Unix(),
|
||||
Identity: identity,
|
||||
Secret: makeSecret(),
|
||||
|
||||
Reference in New Issue
Block a user