mirror of
https://github.com/simon987/task_tracker.git
synced 2025-12-10 21:48:52 +00:00
Reset failed tasks
This commit is contained in:
@@ -98,6 +98,7 @@ func New() *WebAPI {
|
||||
api.router.POST("/project/secret/:id", LogRequestMiddleware(api.SetSecret))
|
||||
api.router.GET("/project/webhook_secret/:id", LogRequestMiddleware(api.GetWebhookSecret))
|
||||
api.router.POST("/project/webhook_secret/:id", LogRequestMiddleware(api.SetWebhookSecret))
|
||||
api.router.POST("/project/reset_failed_tasks/:id", LogRequestMiddleware(api.ResetFailedTasks))
|
||||
|
||||
api.router.POST("/task/submit", LogRequestMiddleware(api.SubmitTask))
|
||||
api.router.GET("/task/get/:project", LogRequestMiddleware(api.GetTaskFromProject))
|
||||
|
||||
@@ -15,7 +15,7 @@ const (
|
||||
type JsonResponse struct {
|
||||
Ok bool `json:"ok"`
|
||||
Message string `json:"message,omitempty"`
|
||||
RateLimitDelay string `json:"rate_limit_delay,omitempty"`
|
||||
RateLimitDelay float64 `json:"rate_limit_delay,omitempty"`
|
||||
Content interface{} `json:"content,omitempty"`
|
||||
}
|
||||
|
||||
@@ -305,6 +305,11 @@ type GetSecretResponse struct {
|
||||
type SetWebhookSecretRequest struct {
|
||||
WebhookSecret string `json:"webhook_secret"`
|
||||
}
|
||||
|
||||
type GetWebhookSecretResponse struct {
|
||||
WebhookSecret string `json:"webhook_secret"`
|
||||
}
|
||||
|
||||
type ResetFailedTaskResponse struct {
|
||||
AffectedTasks int64 `json:"affected_tasks"`
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ func (api *WebAPI) CreateProject(r *Request) {
|
||||
}
|
||||
|
||||
api.Database.SetManagerRoleOn(manager.(*storage.Manager).Id, id,
|
||||
storage.RoleManageAccess|storage.RoleRead|storage.RoleEdit|storage.RoleSecret)
|
||||
storage.RoleManageAccess|storage.RoleRead|storage.RoleEdit|storage.RoleSecret|storage.RoleMaintenance)
|
||||
r.OkJson(JsonResponse{
|
||||
Ok: true,
|
||||
Content: CreateProjectResponse{
|
||||
@@ -209,6 +209,9 @@ func (api *WebAPI) UpdateProject(r *Request) {
|
||||
"project": project,
|
||||
}).Warn("Error during project update")
|
||||
} else {
|
||||
api.SubmitLimiters.Delete(project.Id)
|
||||
api.AssignLimiters.Delete(project.Id)
|
||||
|
||||
r.OkJson(JsonResponse{
|
||||
Ok: true,
|
||||
})
|
||||
@@ -688,3 +691,35 @@ func (api *WebAPI) SetWebhookSecret(r *Request) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (api *WebAPI) ResetFailedTasks(r *Request) {
|
||||
|
||||
pid, err := strconv.ParseInt(r.Ctx.UserValue("id").(string), 10, 64)
|
||||
if err != nil || pid <= 0 {
|
||||
r.Json(JsonResponse{
|
||||
Ok: false,
|
||||
Message: "Invalid project id",
|
||||
}, 400)
|
||||
return
|
||||
}
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
if !isActionOnProjectAuthorized(pid, manager, storage.RoleMaintenance, api.Database) {
|
||||
r.Json(JsonResponse{
|
||||
Ok: false,
|
||||
Message: "Unauthorized",
|
||||
}, 403)
|
||||
return
|
||||
}
|
||||
|
||||
res := api.Database.ResetFailedTasks(pid)
|
||||
|
||||
r.OkJson(JsonResponse{
|
||||
Ok: true,
|
||||
Content: ResetFailedTaskResponse{
|
||||
AffectedTasks: res,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ func (api *WebAPI) SubmitTask(r *Request) {
|
||||
r.Json(JsonResponse{
|
||||
Ok: false,
|
||||
Message: "Too many requests",
|
||||
RateLimitDelay: strconv.FormatFloat(delay, 'f', -1, 64),
|
||||
RateLimitDelay: delay,
|
||||
}, 429)
|
||||
return
|
||||
}
|
||||
@@ -111,7 +111,7 @@ func (api *WebAPI) GetTaskFromProject(r *Request) {
|
||||
r.Json(JsonResponse{
|
||||
Ok: false,
|
||||
Message: "Too many requests",
|
||||
RateLimitDelay: strconv.FormatFloat(delay, 'f', -1, 64),
|
||||
RateLimitDelay: delay,
|
||||
}, 429)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user