package pull import ( pullDao "ai-agent/workflow/dao/pull" pullDto "ai-agent/workflow/model/dto/pull" "context" "github.com/gogf/gf/v2/util/gconv" ) var ActivePullService = &activePullService{} type activePullService struct{} func (s *activePullService) Create(ctx context.Context, req *pullDto.CreateActivePullReq) (res *pullDto.CreateActivePullRes, err error) { id, err := pullDao.ActivePullDao.Insert(ctx, req) if err != nil { return } return &pullDto.CreateActivePullRes{Id: id}, nil } func (s *activePullService) Update(ctx context.Context, req *pullDto.UpdateActivePullReq) (err error) { _, err = pullDao.ActivePullDao.Update(ctx, req) return } func (s *activePullService) Delete(ctx context.Context, req *pullDto.DeleteActivePullReq) (err error) { _, err = pullDao.ActivePullDao.Delete(ctx, req) return } //func (s *activePullService) AllList(ctx context.Context) (err error) { // ctx = context.WithValue(ctx, "user", &beans.User{ // UserName: "admin", // }) // for { // select { // case <-ctx.Done(): // return ctx.Err() // default: // } // // var list []*entity.ActivePull // list, _, err = pullDao.ActivePullDao.ListNative(ctx, &pullDto.ListActivePullReq{}) // if err != nil { // g.Log().Error(ctx, "AllList query failed: %v", err) // time.Sleep(time.Second * 3) // continue // } // // // Get all active pull tasks and check each one for results // for _, item := range list { // var result map[string]any // result, err = flow.PullTaskResult(ctx, item.RequestParament, item.Extension) // if err != nil { // g.Log().Error(ctx, "PullTaskResult failed for item %d: %v", item.Id, err) // continue // } // if !g.IsEmpty(result) { // // Find the task ID that matches the creation pattern // // When created in CreateGatewayTask (flow/lambda_node_util.go), // // the last parameter value extracted from the response becomes the waiting task ID // var id string // if taskId, ok := item.RequestParament["task_id"]; ok { // id = gconv.String(taskId) // } else if requestId, ok := item.RequestParament["id"]; ok { // id = gconv.String(requestId) // } else if jobId, ok := item.RequestParament["job_id"]; ok { // id = gconv.String(jobId) // } else { // // Fallback to original behavior: use last value (matches creation logic) // for _, v := range item.RequestParament { // id = gconv.String(v) // } // } // if id != "" { // flow.Notify(id, result) // // Delete after successful notification // _, _ = pullDao.ActivePullDao.Delete(ctx, &pullDto.DeleteActivePullReq{Id: item.Id}) // } else { // g.Log().Warning(ctx, "AllList: could not extract task ID for item %d", item.Id) // } // } // } // // time.Sleep(time.Second * 10) // } //} func (s *activePullService) List(ctx context.Context, req *pullDto.ListActivePullReq) (res *pullDto.ListActivePullRes, err error) { list, total, err := pullDao.ActivePullDao.List(ctx, req) if err != nil { return nil, err } res = &pullDto.ListActivePullRes{ Total: total, } err = gconv.Struct(list, &res.List) return }