Skip to content

Commit

Permalink
feat: add delete task and list tasks manager api define.
Browse files Browse the repository at this point in the history
Signed-off-by: Asklv <[email protected]>
  • Loading branch information
IRONICBo committed Jul 15, 2024
1 parent bb24243 commit 105e622
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/job/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const (

// SyncPeersJob is the name of syncing peers job.
SyncPeersJob = "sync_peers"

// ListTasksJob is the name of listing tasks job.
ListTasksJob = "list_tasks"

// DeleteTasksJob is the name of deleting tasks job.
DeleteTaskJob = "delete_task"
)

// Machinery server configuration.
Expand Down
28 changes: 28 additions & 0 deletions manager/handlers/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,34 @@ func (h *Handlers) CreateJob(ctx *gin.Context) {
return
}

ctx.JSON(http.StatusOK, job)
case job.DeleteTaskJob:
var json types.CreateDeleteTaskJobRequest
if err := ctx.ShouldBindBodyWith(&json, binding.JSON); err != nil {
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

job, err := h.service.CreateDeleteTaskJob(ctx.Request.Context(), json)
if err != nil {
ctx.Error(err) // nolint: errcheck
return
}

ctx.JSON(http.StatusOK, job)
case job.ListTasksJob:
var json types.CreateListTasksJobRequest
if err := ctx.ShouldBindBodyWith(&json, binding.JSON); err != nil {
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
return
}

job, err := h.service.CreateListTasksJob(ctx.Request.Context(), json)
if err != nil {
ctx.Error(err) // nolint: errcheck
return
}

ctx.JSON(http.StatusOK, job)
default:
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": "Unknow type"})
Expand Down
2 changes: 2 additions & 0 deletions manager/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ type Service interface {
GetConfigs(context.Context, types.GetConfigsQuery) ([]models.Config, int64, error)

CreatePreheatJob(context.Context, types.CreatePreheatJobRequest) (*models.Job, error)
CreateDeleteTaskJob(context.Context, types.CreateDeleteTaskJobRequest) (*models.Job, error)
CreateListTasksJob(context.Context, types.CreateListTasksJobRequest) (*models.Job, error)
DestroyJob(context.Context, uint) error
UpdateJob(context.Context, uint, types.UpdateJobRequest) (*models.Job, error)
GetJob(context.Context, uint) (*models.Job, error)
Expand Down
26 changes: 26 additions & 0 deletions manager/types/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,32 @@ type CreatePreheatJobRequest struct {
SchedulerClusterIDs []uint `json:"scheduler_cluster_ids" binding:"omitempty"`
}

type CreateDeleteTaskJobRequest struct {
BIO string `json:"bio" binding:"omitempty"`
Type string `json:"type" binding:"required"`
Args DeleteTasksJobArgs `json:"args" binding:"omitempty"`
Result map[string]any `json:"result" binding:"omitempty"`
UserID uint `json:"user_id" binding:"omitempty"`
SchedulerClusterIDs []uint `json:"scheduler_cluster_ids" binding:"omitempty"`
}

type DeleteTasksJobArgs struct {
TaskID string `json:"taskID" binding:"required"`
}

type CreateListTasksJobRequest struct {
BIO string `json:"bio" binding:"omitempty"`
Type string `json:"type" binding:"required"`
Args ListTasksJobArgs `json:"args" binding:"omitempty"`
Result map[string]any `json:"result" binding:"omitempty"`
UserID uint `json:"user_id" binding:"omitempty"`
SchedulerClusterIDs []uint `json:"scheduler_cluster_ids" binding:"omitempty"`
}

type ListTasksJobArgs struct {
TaskID string `json:"taskID" binding:"required"`
}

type PreheatArgs struct {
// Type is the preheating type, support image and file.
Type string `json:"type" binding:"required,oneof=image file"`
Expand Down

0 comments on commit 105e622

Please sign in to comment.