add ability to remove user and add task depndencies closes #69
This commit is contained in:
@@ -55,6 +55,8 @@ func handleUpload(handler *Handle) {
|
||||
model, err := GetBaseModel(c.Db, requestData.ModelId)
|
||||
if err != nil {
|
||||
return c.Error500(err)
|
||||
} else if model.CanTrain == 0 {
|
||||
return c.JsonBadRequest("Model can not be trained!")
|
||||
}
|
||||
|
||||
switch model.Status {
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/models"
|
||||
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/models/train"
|
||||
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks/utils"
|
||||
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/users"
|
||||
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
|
||||
)
|
||||
|
||||
@@ -71,6 +72,14 @@ func runner(config Config, db *sql.DB, task_channel chan Task, index int, back_c
|
||||
logger.Error("Failed to tain the model", "error", err)
|
||||
}
|
||||
|
||||
back_channel <- index
|
||||
continue
|
||||
} else if task.TaskType == int(TASK_TYPE_DELETE_USER) {
|
||||
logger.Warn("User deleting Task")
|
||||
if err = DeleteUser(base, task); err != nil {
|
||||
logger.Error("Failed to tain the model", "error", err)
|
||||
}
|
||||
|
||||
back_channel <- index
|
||||
continue
|
||||
}
|
||||
@@ -168,16 +177,23 @@ func RunnerOrchestrator(db *sql.DB, config Config) {
|
||||
}
|
||||
|
||||
if task_to_dispatch == nil {
|
||||
var task Task
|
||||
err := GetDBOnce(db, &task, "tasks where status=$1 limit 1", TASK_TODO)
|
||||
var task TaskT
|
||||
err := GetDBOnce(db, &task, "tasks as t "+
|
||||
// Get depenencies
|
||||
"left join tasks_dependencies as td on t.id=td.main_id "+
|
||||
// Get the task that the depencey resolves to
|
||||
"left join tasks as t2 on t2.id=td.dependent_id "+
|
||||
"where t.status=1 "+
|
||||
"group by t.id having count(td.id) filter (where t2.status in (0,1,2,3)) = 0;")
|
||||
if err != NotFoundError && err != nil {
|
||||
log.Error("Failed to get tasks from db")
|
||||
log.Error("Failed to get tasks from db", "err", err)
|
||||
continue
|
||||
}
|
||||
if err == NotFoundError {
|
||||
task_to_dispatch = nil
|
||||
} else {
|
||||
task_to_dispatch = &task
|
||||
temp := Task(task)
|
||||
task_to_dispatch = &temp
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
type Task struct {
|
||||
Id string `db:"id" json:"id"`
|
||||
UserId string `db:"user_id" json:"user_id"`
|
||||
ModelId string `db:"model_id" json:"model_id"`
|
||||
ModelId *string `db:"model_id" json:"model_id"`
|
||||
Status int `db:"status" json:"status"`
|
||||
StatusMessage string `db:"status_message" json:"status_message"`
|
||||
UserConfirmed int `db:"user_confirmed" json:"user_confirmed"`
|
||||
@@ -21,6 +21,27 @@ type Task struct {
|
||||
CreatedOn time.Time `db:"created_on" json:"created"`
|
||||
}
|
||||
|
||||
// Find better way todo this
|
||||
type TaskT struct {
|
||||
Id string `db:"t.id" json:"id"`
|
||||
UserId string `db:"t.user_id" json:"user_id"`
|
||||
ModelId *string `db:"t.model_id" json:"model_id"`
|
||||
Status int `db:"t.status" json:"status"`
|
||||
StatusMessage string `db:"t.status_message" json:"status_message"`
|
||||
UserConfirmed int `db:"t.user_confirmed" json:"user_confirmed"`
|
||||
Compacted int `db:"t.compacted" json:"compacted"`
|
||||
TaskType int `db:"t.task_type" json:"type"`
|
||||
ExtraTaskInfo string `db:"t.extra_task_info" json:"extra_task_info"`
|
||||
Result string `db:"t.result" json:"result"`
|
||||
CreatedOn time.Time `db:"t.created_on" json:"created"`
|
||||
}
|
||||
|
||||
type TaskDependents struct {
|
||||
Id string `db:"id" json:"id"`
|
||||
MainId string `db:"main_id" json:"main_id"`
|
||||
DependentId string `db:"dependent_id" json:"dependent_id"`
|
||||
}
|
||||
|
||||
type TaskStatus int
|
||||
|
||||
const (
|
||||
@@ -39,6 +60,7 @@ const (
|
||||
TASK_TYPE_CLASSIFICATION TaskType = 1 + iota
|
||||
TASK_TYPE_TRAINING
|
||||
TASK_TYPE_RETRAINING
|
||||
TASK_TYPE_DELETE_USER
|
||||
)
|
||||
|
||||
type TaskAgreement int
|
||||
@@ -82,3 +104,15 @@ func (t Task) SetResult(base BasePack, result any) (err error) {
|
||||
_, err = base.GetDb().Exec("update tasks set result=$1 where id=$2", text, t.Id)
|
||||
return
|
||||
}
|
||||
|
||||
func (t Task) Depend(base BasePack, depend_id string) (err error) {
|
||||
var dependency = struct {
|
||||
Main string `db:"main_id"`
|
||||
Dependent string `db:"dependent_id"`
|
||||
}{
|
||||
Main: t.Id,
|
||||
Dependent: depend_id,
|
||||
}
|
||||
_, err = InsertReturnId(base.GetDb(), &dependency, "tasks_dependencies", "id")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user