Skip to content

Commit

Permalink
🐛 Fix task group update. (#645)
Browse files Browse the repository at this point in the history
Fix task group submit.
Update to follow error reporting pattern.

---------

Signed-off-by: Jeff Ortel <jortel@redhat.com>
  • Loading branch information
jortel authored Jun 6, 2024
1 parent a9e5621 commit 01b8079
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
4 changes: 2 additions & 2 deletions api/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ func (h TaskHandler) Create(ctx *gin.Context) {
task.With(r.Model())
task.CreateUser = h.BaseHandler.CurrentUser(ctx)
rtx := WithContext(ctx)
created, err := rtx.TaskManager.Create(h.DB(ctx), task)
err = rtx.TaskManager.Create(h.DB(ctx), task)
if err != nil {
_ = ctx.Error(err)
return
}

r.With(created.Task)
r.With(task.Task)

h.Respond(ctx, http.StatusCreated, r)
}
Expand Down
28 changes: 18 additions & 10 deletions api/taskgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,16 @@ func (h TaskGroupHandler) Create(ctx *gin.Context) {
for i := range m.Tasks {
task := &tasking.Task{}
task.With(&m.Tasks[i])
task, err = rtx.TaskManager.Create(h.DB(ctx), task)
err = rtx.TaskManager.Create(h.DB(ctx), task)
if err != nil {
_ = ctx.Error(err)
return
}
}
default:
h.Respond(ctx,
http.StatusBadRequest,
gin.H{
"error": "state must be ('''|Created|Ready)",
_ = ctx.Error(
&BadRequestError{
Reason: "state must be ('''|Created|Ready)",
})
return
}
Expand Down Expand Up @@ -208,6 +207,16 @@ func (h TaskGroupHandler) Update(ctx *gin.Context) {
return
}
case tasking.Ready:
for i := range m.Tasks {
task := &m.Tasks[i]
if task.ID > 0 {
_ = ctx.Error(
&BadRequestError{
Reason: "already submitted.",
})
return
}
}
err := m.Propagate()
if err != nil {
return
Expand All @@ -221,17 +230,16 @@ func (h TaskGroupHandler) Update(ctx *gin.Context) {
for i := range m.Tasks {
task := &tasking.Task{}
task.With(&m.Tasks[i])
err = rtx.TaskManager.Update(h.DB(ctx), task)
err = rtx.TaskManager.Create(h.DB(ctx), task)
if err != nil {
_ = ctx.Error(err)
return
}
}
default:
h.Respond(ctx,
http.StatusBadRequest,
gin.H{
"error": "state must be (Created|Ready)",
_ = ctx.Error(
&BadRequestError{
Reason: "state must be (Created|Ready)",
})
return
}
Expand Down
7 changes: 4 additions & 3 deletions task/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ func (m *Manager) Run(ctx context.Context) {
}

// Create a task.
func (m *Manager) Create(db *gorm.DB, requested *Task) (task *Task, err error) {
task = &Task{&model.Task{}}
func (m *Manager) Create(db *gorm.DB, requested *Task) (err error) {
task := &Task{&model.Task{}}
switch requested.State {
case "":
requested.State = Created
Expand Down Expand Up @@ -161,6 +161,7 @@ func (m *Manager) Create(db *gorm.DB, requested *Task) (task *Task, err error) {
err = liberr.Wrap(err)
return
}
requested.Task = task.Task
return
}

Expand All @@ -172,7 +173,7 @@ func (m *Manager) Update(db *gorm.DB, requested *Task) (err error) {
if err != nil {
return
}
switch requested.State {
switch task.State {
case Created,
Ready:
task.UpdateUser = requested.UpdateUser
Expand Down

0 comments on commit 01b8079

Please sign in to comment.