scheduled_test_port.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. )
  6. // ScheduledTestPlan represents a scheduled test plan domain model.
  7. type ScheduledTestPlan struct {
  8. ID int64 `json:"id"`
  9. AccountID int64 `json:"account_id"`
  10. ModelID string `json:"model_id"`
  11. CronExpression string `json:"cron_expression"`
  12. Enabled bool `json:"enabled"`
  13. MaxResults int `json:"max_results"`
  14. AutoRecover bool `json:"auto_recover"`
  15. LastRunAt *time.Time `json:"last_run_at"`
  16. NextRunAt *time.Time `json:"next_run_at"`
  17. CreatedAt time.Time `json:"created_at"`
  18. UpdatedAt time.Time `json:"updated_at"`
  19. }
  20. // ScheduledTestResult represents a single test execution result.
  21. type ScheduledTestResult struct {
  22. ID int64 `json:"id"`
  23. PlanID int64 `json:"plan_id"`
  24. Status string `json:"status"`
  25. ResponseText string `json:"response_text"`
  26. ErrorMessage string `json:"error_message"`
  27. LatencyMs int64 `json:"latency_ms"`
  28. StartedAt time.Time `json:"started_at"`
  29. FinishedAt time.Time `json:"finished_at"`
  30. CreatedAt time.Time `json:"created_at"`
  31. }
  32. // ScheduledTestPlanRepository defines the data access interface for test plans.
  33. type ScheduledTestPlanRepository interface {
  34. Create(ctx context.Context, plan *ScheduledTestPlan) (*ScheduledTestPlan, error)
  35. GetByID(ctx context.Context, id int64) (*ScheduledTestPlan, error)
  36. ListByAccountID(ctx context.Context, accountID int64) ([]*ScheduledTestPlan, error)
  37. ListDue(ctx context.Context, now time.Time) ([]*ScheduledTestPlan, error)
  38. Update(ctx context.Context, plan *ScheduledTestPlan) (*ScheduledTestPlan, error)
  39. Delete(ctx context.Context, id int64) error
  40. UpdateAfterRun(ctx context.Context, id int64, lastRunAt time.Time, nextRunAt time.Time) error
  41. }
  42. // ScheduledTestResultRepository defines the data access interface for test results.
  43. type ScheduledTestResultRepository interface {
  44. Create(ctx context.Context, result *ScheduledTestResult) (*ScheduledTestResult, error)
  45. ListByPlanID(ctx context.Context, planID int64, limit int) ([]*ScheduledTestResult, error)
  46. PruneOldResults(ctx context.Context, planID int64, keepCount int) error
  47. }