36 lines
961 B
Go
36 lines
961 B
Go
|
|
package job
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
domusecase "haixun-backend/internal/model/job/domain/usecase"
|
||
|
|
"haixun-backend/internal/svc"
|
||
|
|
"haixun-backend/internal/types"
|
||
|
|
)
|
||
|
|
|
||
|
|
type CreateJobScheduleLogic struct {
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewCreateJobScheduleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateJobScheduleLogic {
|
||
|
|
return &CreateJobScheduleLogic{ctx: ctx, svcCtx: svcCtx}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *CreateJobScheduleLogic) CreateJobSchedule(req *types.CreateJobScheduleReq) (*types.JobScheduleData, error) {
|
||
|
|
schedule, err := l.svcCtx.Job.CreateSchedule(l.ctx, domusecase.CreateScheduleRequest{
|
||
|
|
TemplateType: req.TemplateType,
|
||
|
|
Scope: req.Scope,
|
||
|
|
ScopeID: req.ScopeID,
|
||
|
|
Cron: req.Cron,
|
||
|
|
Timezone: req.Timezone,
|
||
|
|
PayloadTemplate: req.PayloadTemplate,
|
||
|
|
Enabled: req.Enabled,
|
||
|
|
})
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
data := toJobScheduleData(schedule)
|
||
|
|
return &data, nil
|
||
|
|
}
|