mirror of
https://github.com/simon987/task_tracker.git
synced 2025-04-19 18:16:45 +00:00
Implement hard reset button
This commit is contained in:
parent
9b8184e414
commit
687ecdbbce
@ -105,6 +105,7 @@ func New() *WebAPI {
|
|||||||
api.router.GET("/project/webhook_secret/:id", LogRequestMiddleware(api.GetWebhookSecret))
|
api.router.GET("/project/webhook_secret/:id", LogRequestMiddleware(api.GetWebhookSecret))
|
||||||
api.router.POST("/project/webhook_secret/:id", LogRequestMiddleware(api.SetWebhookSecret))
|
api.router.POST("/project/webhook_secret/:id", LogRequestMiddleware(api.SetWebhookSecret))
|
||||||
api.router.POST("/project/reset_failed_tasks/:id", LogRequestMiddleware(api.ResetFailedTasks))
|
api.router.POST("/project/reset_failed_tasks/:id", LogRequestMiddleware(api.ResetFailedTasks))
|
||||||
|
api.router.POST("/project/hard_reset/:id", LogRequestMiddleware(api.HardReset))
|
||||||
|
|
||||||
api.router.POST("/task/submit", LogRequestMiddleware(api.SubmitTask))
|
api.router.POST("/task/submit", LogRequestMiddleware(api.SubmitTask))
|
||||||
api.router.GET("/task/get/:project", LogRequestMiddleware(api.GetTaskFromProject))
|
api.router.GET("/task/get/:project", LogRequestMiddleware(api.GetTaskFromProject))
|
||||||
|
@ -314,3 +314,7 @@ type GetWebhookSecretResponse struct {
|
|||||||
type ResetFailedTaskResponse struct {
|
type ResetFailedTaskResponse struct {
|
||||||
AffectedTasks int64 `json:"affected_tasks"`
|
AffectedTasks int64 `json:"affected_tasks"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type HardResetResponse struct {
|
||||||
|
AffectedTasks int64 `json:"affected_tasks"`
|
||||||
|
}
|
||||||
|
@ -724,3 +724,35 @@ func (api *WebAPI) ResetFailedTasks(r *Request) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *WebAPI) HardReset(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.HardReset(pid)
|
||||||
|
|
||||||
|
r.OkJson(JsonResponse{
|
||||||
|
Ok: true,
|
||||||
|
Content: HardResetResponse{
|
||||||
|
AffectedTasks: res,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -32,3 +32,21 @@ func (database *Database) ResetTimedOutTasks() {
|
|||||||
"rowsAffected": rowsAffected,
|
"rowsAffected": rowsAffected,
|
||||||
}).Info("Reset timed out tasks")
|
}).Info("Reset timed out tasks")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (database Database) HardReset(pid int64) int64 {
|
||||||
|
|
||||||
|
db := database.getDB()
|
||||||
|
|
||||||
|
_, err := db.Exec(`UPDATE task SET assignee=NULL WHERE project=$1`, pid)
|
||||||
|
handleErr(err)
|
||||||
|
res, err := db.Exec(`DELETE FROM task WHERE project=$1`, pid)
|
||||||
|
|
||||||
|
rowsAffected, _ := res.RowsAffected()
|
||||||
|
|
||||||
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"rowsAffected": rowsAffected,
|
||||||
|
"project": pid,
|
||||||
|
}).Info("Hard reset")
|
||||||
|
|
||||||
|
return rowsAffected
|
||||||
|
}
|
||||||
|
@ -118,4 +118,8 @@ export class ApiService {
|
|||||||
return this.http.post(this.url + `/project/reset_failed_tasks/${pid}`, null, this.options);
|
return this.http.post(this.url + `/project/reset_failed_tasks/${pid}`, null, this.options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hardReset(pid: number) {
|
||||||
|
return this.http.post(this.url + `/project/hard_reset/${pid}`, null, this.options);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -414,6 +414,7 @@ export class ProjectDashboardComponent implements OnInit {
|
|||||||
this.dialog.open(AreYouSureComponent, {
|
this.dialog.open(AreYouSureComponent, {
|
||||||
width: '250px',
|
width: '250px',
|
||||||
}).afterClosed().subscribe(result => {
|
}).afterClosed().subscribe(result => {
|
||||||
|
if (result) {
|
||||||
this.project.paused = paused;
|
this.project.paused = paused;
|
||||||
this.apiService.updateProject(this.project).subscribe(() => {
|
this.apiService.updateProject(this.project).subscribe(() => {
|
||||||
this.translate.get('messenger.acknowledged').subscribe(t =>
|
this.translate.get('messenger.acknowledged').subscribe(t =>
|
||||||
@ -422,10 +423,23 @@ export class ProjectDashboardComponent implements OnInit {
|
|||||||
this.translate.get('messenger.unauthorized').subscribe(t =>
|
this.translate.get('messenger.unauthorized').subscribe(t =>
|
||||||
this.messenger.show(t));
|
this.messenger.show(t));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
hardReset() {
|
hardReset() {
|
||||||
|
this.dialog.open(AreYouSureComponent, {
|
||||||
|
width: '250px',
|
||||||
|
}).afterClosed().subscribe(result => {
|
||||||
|
if (result) {
|
||||||
|
this.apiService.hardReset(this.project.id).subscribe(data => {
|
||||||
|
this.translate.get('project.hard_reset_response').subscribe(t =>
|
||||||
|
this.messenger.show(t + data['content']['affected_tasks']));
|
||||||
|
}, error => {
|
||||||
|
this.translate.get('messenger.unauthorized').subscribe(t =>
|
||||||
|
this.messenger.show(t));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,7 @@
|
|||||||
"version": "Git version (commit hash)",
|
"version": "Git version (commit hash)",
|
||||||
"secret": "Secret",
|
"secret": "Secret",
|
||||||
"reset_response": "Reset failed tasks: ",
|
"reset_response": "Reset failed tasks: ",
|
||||||
|
"hard_reset_response": "Deleted tasks: ",
|
||||||
"assign_rate": "Task assign rate limit",
|
"assign_rate": "Task assign rate limit",
|
||||||
"submit_rate": "Task submit rate limit",
|
"submit_rate": "Task submit rate limit",
|
||||||
"rate": "per second",
|
"rate": "per second",
|
||||||
|
@ -71,6 +71,7 @@
|
|||||||
"manager_select": "Donner accès à",
|
"manager_select": "Donner accès à",
|
||||||
"version": "Version git (hash du commit)",
|
"version": "Version git (hash du commit)",
|
||||||
"reset_response": "Réinitialisé les tâches en échec: ",
|
"reset_response": "Réinitialisé les tâches en échec: ",
|
||||||
|
"hard_reset_response": "Supprimé toutes les tâches: ",
|
||||||
"assign_rate": "Taux d'assignation de tâches",
|
"assign_rate": "Taux d'assignation de tâches",
|
||||||
"submit_rate": "Taux de soumission de tâches",
|
"submit_rate": "Taux de soumission de tâches",
|
||||||
"rate": "par seconde",
|
"rate": "par seconde",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user