1
0

workflow.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package models
  2. import (
  3. "time"
  4. )
  5. // WorkflowTemplate - JSON-configurable workflow definition (admin-managed)
  6. type WorkflowTemplate struct {
  7. ID uint `gorm:"primaryKey"`
  8. Name string `gorm:"size:200;not null;uniqueIndex"`
  9. Description string `gorm:"type:text"`
  10. Definition string `gorm:"type:text;not null"` // JSON DAG definition
  11. IsActive bool `gorm:"default:true"`
  12. CreatedByID uint
  13. CreatedBy User `gorm:"foreignKey:CreatedByID"`
  14. CreatedAt time.Time
  15. UpdatedAt time.Time
  16. }
  17. // WorkflowInstance - a running instance of a workflow (many-to-one with Service)
  18. type WorkflowInstance struct {
  19. ID uint `gorm:"primaryKey"`
  20. WorkflowTemplateID uint
  21. WorkflowTemplate WorkflowTemplate `gorm:"foreignKey:WorkflowTemplateID"`
  22. Status string `gorm:"size:50;not null"` // "running", "completed", "failed", "paused"
  23. Context string `gorm:"type:text"` // JSON workflow variables
  24. ServiceID *uint // Many-to-one: multiple workflows can belong to one service
  25. Service *Service `gorm:"foreignKey:ServiceID"`
  26. CreatedAt time.Time
  27. UpdatedAt time.Time
  28. CompletedAt *time.Time
  29. }
  30. // WorkflowNode - represents a task node in a workflow instance
  31. type WorkflowNode struct {
  32. ID uint `gorm:"primaryKey"`
  33. WorkflowInstanceID uint
  34. WorkflowInstance WorkflowInstance `gorm:"foreignKey:WorkflowInstanceID"`
  35. NodeKey string `gorm:"size:100;not null"`
  36. NodeType string `gorm:"size:50;not null"` // "task", "condition", "parallel", "join"
  37. Status string `gorm:"size:50;not null"` // "pending", "ready", "running", "completed", "skipped", "failed"
  38. TaskID *uint // Link to created task (assignment is on Task)
  39. Task *Task `gorm:"foreignKey:TaskID"`
  40. RetryCount int `gorm:"default:0"`
  41. InputData string `gorm:"type:text"`
  42. OutputData string `gorm:"type:text"`
  43. CreatedAt time.Time
  44. UpdatedAt time.Time
  45. StartedAt *time.Time
  46. CompletedAt *time.Time
  47. }
  48. // WorkflowEdge - dependency between nodes
  49. type WorkflowEdge struct {
  50. ID uint `gorm:"primaryKey"`
  51. WorkflowInstanceID uint
  52. FromNodeID uint
  53. FromNode WorkflowNode `gorm:"foreignKey:FromNodeID"`
  54. ToNodeID uint
  55. ToNode WorkflowNode `gorm:"foreignKey:ToNodeID"`
  56. Condition string `gorm:"type:text"`
  57. }