phase.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package pipeline
  2. import (
  3. "context"
  4. "spider/internal/model"
  5. )
  6. // Settings is a minimal interface satisfied by *service.SettingsService.
  7. // Using an interface here avoids an import cycle (service → worker → pipeline → service).
  8. type Settings interface {
  9. GetInt(ctx context.Context, key string, defaultVal int) int
  10. GetFloat(ctx context.Context, key string, defaultVal float64) float64
  11. GetBool(ctx context.Context, key string, defaultVal bool) bool
  12. }
  13. // Phase 每个采集阶段的接口
  14. type Phase interface {
  15. Name() string
  16. Run(ctx context.Context, task *model.Task, opts *Options) error
  17. }
  18. // Options Pipeline 执行选项(来自任务参数)
  19. type Options struct {
  20. Target string
  21. SkipPhases []string
  22. TestRun *TestRun
  23. }
  24. type TestRun struct {
  25. ItemLimit int
  26. MessageLimit int
  27. }
  28. // ProgressReporter 进度上报函数类型
  29. // 由 pipeline.Runner 提供,各 phase 调用
  30. type ProgressReporter func(phase string, current, total int, message string)
  31. // ShouldSkip 检查某阶段是否被跳过
  32. func ShouldSkip(phaseName string, skipPhases []string) bool {
  33. for _, s := range skipPhases {
  34. if s == phaseName {
  35. return true
  36. }
  37. }
  38. return false
  39. }