details improvement and unnecessary files deletion

This commit is contained in:
yoan
2024-11-24 13:36:17 +08:00
parent 37df882ed3
commit 9ff3e22c80
57 changed files with 978 additions and 5047 deletions

View File

@@ -12,6 +12,7 @@ import (
type WorkflowRepository interface {
Get(ctx context.Context, id string) (*domain.Workflow, error)
SaveRunLog(ctx context.Context, log *domain.WorkflowRunLog) error
ListEnabledAuto(ctx context.Context) ([]domain.Workflow, error)
}
type WorkflowService struct {
@@ -24,6 +25,29 @@ func NewWorkflowService(repo WorkflowRepository) *WorkflowService {
}
}
func (s *WorkflowService) InitSchedule(ctx context.Context) error {
// 查询所有的 enabled auto workflow
workflows, err := s.repo.ListEnabledAuto(ctx)
if err != nil {
return err
}
scheduler := app.GetScheduler()
for _, workflow := range workflows {
err := scheduler.Add(workflow.Id, workflow.Crontab, func() {
s.Run(ctx, &domain.WorkflowRunReq{
Id: workflow.Id,
})
})
if err != nil {
app.GetApp().Logger().Error("failed to add schedule", "err", err)
return err
}
}
scheduler.Start()
app.GetApp().Logger().Info("workflow schedule started")
return nil
}
func (s *WorkflowService) Run(ctx context.Context, req *domain.WorkflowRunReq) error {
// 查询
if req.Id == "" {