Skip to content

Commit

Permalink
Merge pull request #444 from openinfradev/fix-latest-task-api
Browse files Browse the repository at this point in the history
bugfix: relate task with parent app on create job
  • Loading branch information
ktkfree authored Apr 29, 2024
2 parents 3ce4f20 + edebf72 commit 7806b7b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 5 additions & 2 deletions internal/repository/app-serve-app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type IAppServeAppRepository interface {

IsAppServeAppExist(ctx context.Context, appId string) (int64, error)
IsAppServeAppNameExist(ctx context.Context, orgId string, appName string) (int64, error)
CreateTask(ctx context.Context, task *model.AppServeAppTask) (taskId string, err error)
CreateTask(ctx context.Context, task *model.AppServeAppTask, appId string) (taskId string, err error)
UpdateStatus(ctx context.Context, appId string, taskId string, status string, output string) error
UpdateEndpoint(ctx context.Context, appId string, taskId string, endpoint string, previewEndpoint string, helmRevision int32) error
GetTaskCountById(ctx context.Context, appId string) (int64, error)
Expand All @@ -53,8 +53,11 @@ func (r *AppServeAppRepository) CreateAppServeApp(ctx context.Context, app *mode
}

// Update creates new appServeApp task for existing appServeApp.
func (r *AppServeAppRepository) CreateTask(ctx context.Context, task *model.AppServeAppTask) (string, error) {
func (r *AppServeAppRepository) CreateTask(ctx context.Context, task *model.AppServeAppTask, appId string) (string, error) {
task.ID = uuid.New().String()
if len(appId) > 0 {
task.AppServeAppId = appId
}
res := r.db.WithContext(ctx).Create(task)
if res.Error != nil {
return "", res.Error
Expand Down
9 changes: 5 additions & 4 deletions internal/usecase/app-serve-app.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (u *AppServeAppUsecase) CreateAppServeApp(ctx context.Context, app *model.A
return "", "", errors.Wrap(err, "Failed to create app.")
}

taskId, err := u.repo.CreateTask(ctx, task)
taskId, err := u.repo.CreateTask(ctx, task, appId)
if err != nil {
log.Error(ctx, err)
return "", "", errors.Wrap(err, "Failed to create task.")
Expand Down Expand Up @@ -395,7 +395,7 @@ func (u *AppServeAppUsecase) DeleteAppServeApp(ctx context.Context, appId string
CreatedAt: time.Now(),
}

taskId, err := u.repo.CreateTask(ctx, appTask)
taskId, err := u.repo.CreateTask(ctx, appTask, "")
if err != nil {
log.Error(ctx, "taskId = ", taskId)
log.Error(ctx, "Failed to create delete task. Err:", err)
Expand Down Expand Up @@ -503,7 +503,8 @@ func (u *AppServeAppUsecase) UpdateAppServeApp(ctx context.Context, appId string
log.Debug(ctx, "After transform, extraEnv: ", extEnv)
}

taskId, err := u.repo.CreateTask(ctx, appTask)
// TODO: Check if appId is necessary here.
taskId, err := u.repo.CreateTask(ctx, appTask, appId)
if err != nil {
log.Info(ctx, "taskId = ", taskId)
return "", fmt.Errorf("failed to update app-serve application. Err: %s", err)
Expand Down Expand Up @@ -728,7 +729,7 @@ func (u *AppServeAppUsecase) RollbackAppServeApp(ctx context.Context, appId stri
task.RollbackVersion = targetVer

// Creates new task record from the target task
newTaskId, err := u.repo.CreateTask(ctx, task)
newTaskId, err := u.repo.CreateTask(ctx, task, "")
if err != nil {
log.Info(ctx, "taskId = ", newTaskId)
return "", fmt.Errorf("failed to rollback app-serve application. Err: %s", err)
Expand Down

0 comments on commit 7806b7b

Please sign in to comment.