1234567891011121314151617181920212223242526272829303132333435 |
- package task
- import (
- logger "eta/eta_mini_ht_api/common/component/log"
- "eta/eta_mini_ht_api/models/task"
- )
- type TaskDTO struct {
- TaskType string
- Detail string
- }
- func InitAndStartTask(dto TaskDTO) (taskId int, err error) {
- initTask := convertToTask(dto)
- initTask.Status = task.StatusProcess
- taskId, err = task.InitTask(initTask)
- if err != nil {
- logger.Error("创建任务记录失败:%v", err)
- return
- }
- return
- }
- func UpdateAndFailedTask(taskId int, detail string) {
- task.UpdateDetailsAndStatusById(taskId, task.StatusFailed, detail)
- }
- func UpdateAndSuccessTask(taskId int, detail string) {
- task.UpdateDetailsAndStatusById(taskId, task.StatusSuccess, detail)
- }
- func convertToTask(dto TaskDTO) task.Task {
- return task.Task{
- TaskType: dto.TaskType,
- Details: dto.Detail,
- }
- }
|