mirror of
https://github.com/simon987/task_tracker.git
synced 2025-04-18 01:46:45 +00:00
Don't give rate limit delay when project is not found
This commit is contained in:
parent
15a3e66b70
commit
d62c70e1be
@ -11,7 +11,7 @@ func (api *WebAPI) ReserveSubmit(pid int64) *rate.Reservation {
|
|||||||
if !ok {
|
if !ok {
|
||||||
project := api.Database.GetProject(pid)
|
project := api.Database.GetProject(pid)
|
||||||
if project == nil {
|
if project == nil {
|
||||||
return &rate.Reservation{}
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
limiter = rate.NewLimiter(project.SubmitRate, 1)
|
limiter = rate.NewLimiter(project.SubmitRate, 1)
|
||||||
@ -27,7 +27,7 @@ func (api *WebAPI) ReserveAssign(pid int64) *rate.Reservation {
|
|||||||
if !ok {
|
if !ok {
|
||||||
project := api.Database.GetProject(pid)
|
project := api.Database.GetProject(pid)
|
||||||
if project == nil {
|
if project == nil {
|
||||||
return &rate.Reservation{}
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
limiter = rate.NewLimiter(project.AssignRate, 1)
|
limiter = rate.NewLimiter(project.AssignRate, 1)
|
||||||
|
14
api/task.go
14
api/task.go
@ -56,6 +56,13 @@ func (api *WebAPI) SubmitTask(r *Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reservation := api.ReserveSubmit(createReq.Project)
|
reservation := api.ReserveSubmit(createReq.Project)
|
||||||
|
if reservation == nil {
|
||||||
|
r.Json(JsonResponse{
|
||||||
|
Ok: false,
|
||||||
|
Message: "Project not found",
|
||||||
|
}, 404)
|
||||||
|
return
|
||||||
|
}
|
||||||
delay := reservation.DelayFrom(time.Now()).Seconds()
|
delay := reservation.DelayFrom(time.Now()).Seconds()
|
||||||
if delay > 0 {
|
if delay > 0 {
|
||||||
r.Json(JsonResponse{
|
r.Json(JsonResponse{
|
||||||
@ -108,6 +115,13 @@ func (api *WebAPI) GetTaskFromProject(r *Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reservation := api.ReserveAssign(project)
|
reservation := api.ReserveAssign(project)
|
||||||
|
if reservation == nil {
|
||||||
|
r.Json(JsonResponse{
|
||||||
|
Ok: false,
|
||||||
|
Message: "Project not found",
|
||||||
|
}, 404)
|
||||||
|
return
|
||||||
|
}
|
||||||
delay := reservation.DelayFrom(time.Now()).Seconds()
|
delay := reservation.DelayFrom(time.Now()).Seconds()
|
||||||
if delay > 0 {
|
if delay > 0 {
|
||||||
r.Json(JsonResponse{
|
r.Json(JsonResponse{
|
||||||
|
@ -899,6 +899,26 @@ func TestTaskChainCausesConflict(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTaskAssignInvalidDoesntGiveRateLimit(t *testing.T) {
|
||||||
|
|
||||||
|
task := getTaskFromProject(13247, testWorker)
|
||||||
|
|
||||||
|
if task.RateLimitDelay != 0 {
|
||||||
|
t.Error()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTaskSubmitInvalidDoesntGiveRateLimit(t *testing.T) {
|
||||||
|
|
||||||
|
resp := createTask(api.SubmitTaskRequest{
|
||||||
|
Recipe: " ",
|
||||||
|
Project: 133453,
|
||||||
|
}, testWorker)
|
||||||
|
|
||||||
|
if resp.RateLimitDelay != 0 {
|
||||||
|
t.Error()
|
||||||
|
}
|
||||||
|
}
|
||||||
func createTask(request api.SubmitTaskRequest, worker *storage.Worker) (ar api.JsonResponse) {
|
func createTask(request api.SubmitTaskRequest, worker *storage.Worker) (ar api.JsonResponse) {
|
||||||
r := Post("/task/submit", request, worker, nil)
|
r := Post("/task/submit", request, worker, nil)
|
||||||
UnmarshalResponse(r, &ar)
|
UnmarshalResponse(r, &ar)
|
||||||
|
@ -168,9 +168,10 @@ type ProjectListAR struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TaskAR struct {
|
type TaskAR struct {
|
||||||
Ok bool `json:"ok"`
|
Ok bool `json:"ok"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
Content struct {
|
RateLimitDelay float64 `json:"rate_limit_delay,omitempty"`
|
||||||
|
Content struct {
|
||||||
Task *storage.Task `json:"task"`
|
Task *storage.Task `json:"task"`
|
||||||
} `json:"content"`
|
} `json:"content"`
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user