flow

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecutionStatus

type ExecutionStatus int

ExecutionStatus represents the status of a workflow execution

const (
	ExecutionStatusPending ExecutionStatus = iota
	ExecutionStatusRunning
	ExecutionStatusCompleted
	ExecutionStatusFailed
	ExecutionStatusCancelled
)

func (ExecutionStatus) String

func (e ExecutionStatus) String() string

String returns the string representation of ExecutionStatus

type JSONMap

type JSONMap map[string]interface{}

JSONMap is a custom type for handling JSON maps in GORM

func (*JSONMap) Scan

func (j *JSONMap) Scan(value interface{}) error

Scan implements the Scanner interface for database deserialization

func (JSONMap) Value

func (j JSONMap) Value() (driver.Value, error)

Value implements the Valuer interface for database serialization

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service provides workflow management functionality

func NewService

func NewService() *Service

NewService creates a new flow service

func (*Service) CancelExecution

func (s *Service) CancelExecution(ctx context.Context, userID string, executionID uint) error

CancelExecution cancels a running workflow execution

func (*Service) CreateWorkflow

func (s *Service) CreateWorkflow(ctx context.Context, workflow *Workflow) error

CreateWorkflow creates a new workflow

func (*Service) DeleteWorkflow

func (s *Service) DeleteWorkflow(ctx context.Context, userID string, workflowID uint) error

DeleteWorkflow deletes a workflow

func (*Service) ExecuteWorkflow

func (s *Service) ExecuteWorkflow(ctx context.Context, userID string, workflowID uint, input map[string]interface{}) (*WorkflowExecution, error)

ExecuteWorkflow starts a new workflow execution

func (*Service) GetExecutionStatus

func (s *Service) GetExecutionStatus(ctx context.Context, userID string, executionID uint) (*WorkflowExecution, error)

GetExecutionStatus retrieves the status of a workflow execution

func (*Service) GetWorkflow

func (s *Service) GetWorkflow(ctx context.Context, userID string, workflowID uint) (*Workflow, error)

GetWorkflow retrieves a workflow by ID

func (*Service) ListExecutions

func (s *Service) ListExecutions(ctx context.Context, userID string, workflowID uint) ([]*WorkflowExecution, error)

ListExecutions returns all executions for a workflow

func (*Service) ListWorkflows

func (s *Service) ListWorkflows(ctx context.Context, userID string) ([]*Workflow, error)

ListWorkflows returns all workflows for a user

func (*Service) SetDB

func (s *Service) SetDB(db *gorm.DB)

SetDB sets the database connection

func (*Service) UpdateWorkflow

func (s *Service) UpdateWorkflow(ctx context.Context, userID string, workflow *Workflow) error

UpdateWorkflow updates an existing workflow

type StepExecution

type StepExecution struct {
	ID          uint            `json:"id" gorm:"primaryKey"`
	ExecutionID uint            `json:"execution_id" gorm:"index;not null"`
	StepID      uint            `json:"step_id" gorm:"index;not null"`
	Status      ExecutionStatus `json:"status" gorm:"default:0"`
	Input       JSONMap         `json:"input" gorm:"type:text"`
	Output      JSONMap         `json:"output" gorm:"type:text"`
	Error       string          `json:"error"`
	StartedAt   time.Time       `json:"started_at"`
	CompletedAt *time.Time      `json:"completed_at"`
	Attempt     int             `json:"attempt" gorm:"default:1"`
}

StepExecution represents the execution of a workflow step

func (StepExecution) TableName

func (StepExecution) TableName() string

TableName returns the table name for the StepExecution model

type StepType

type StepType int

StepType represents the type of a workflow step

const (
	StepTypeCommand StepType = iota
	StepTypeHTTP
	StepTypeScript
	StepTypeCondition
	StepTypeLoop
	StepTypeParallel
)

func (StepType) String

func (s StepType) String() string

String returns the string representation of StepType

type Workflow

type Workflow struct {
	ID          uint           `json:"id" gorm:"primaryKey"`
	Name        string         `json:"name" gorm:"not null"`
	Description string         `json:"description"`
	UserID      string         `json:"user_id" gorm:"index;not null"`
	Status      WorkflowStatus `json:"status" gorm:"default:0"`
	Steps       []WorkflowStep `json:"steps" gorm:"foreignKey:WorkflowID;constraint:OnDelete:CASCADE"`
	Variables   JSONMap        `json:"variables" gorm:"type:text"`
	CreatedAt   time.Time      `json:"created_at"`
	UpdatedAt   time.Time      `json:"updated_at"`
	DeletedAt   gorm.DeletedAt `json:"-" gorm:"index"`
}

Workflow represents a workflow definition

func (Workflow) TableName

func (Workflow) TableName() string

TableName returns the table name for the Workflow model

type WorkflowExecution

type WorkflowExecution struct {
	ID          uint            `json:"id" gorm:"primaryKey"`
	WorkflowID  uint            `json:"workflow_id" gorm:"index;not null"`
	UserID      string          `json:"user_id" gorm:"index;not null"`
	Status      ExecutionStatus `json:"status" gorm:"default:0"`
	Input       JSONMap         `json:"input" gorm:"type:text"`
	Output      JSONMap         `json:"output" gorm:"type:text"`
	Error       string          `json:"error"`
	StartedAt   time.Time       `json:"started_at"`
	CompletedAt *time.Time      `json:"completed_at"`
	Steps       []StepExecution `json:"steps" gorm:"foreignKey:ExecutionID;constraint:OnDelete:CASCADE"`
}

WorkflowExecution represents an execution of a workflow

func (WorkflowExecution) TableName

func (WorkflowExecution) TableName() string

TableName returns the table name for the WorkflowExecution model

type WorkflowStatus

type WorkflowStatus int

WorkflowStatus represents the status of a workflow

const (
	WorkflowStatusDraft WorkflowStatus = iota
	WorkflowStatusActive
	WorkflowStatusInactive
)

func (WorkflowStatus) String

func (w WorkflowStatus) String() string

String returns the string representation of WorkflowStatus

type WorkflowStep

type WorkflowStep struct {
	ID         uint      `json:"id" gorm:"primaryKey"`
	WorkflowID uint      `json:"workflow_id" gorm:"index;not null"`
	Name       string    `json:"name" gorm:"not null"`
	Type       StepType  `json:"type" gorm:"not null"`
	Config     JSONMap   `json:"config" gorm:"type:text"`
	Order      int       `json:"order" gorm:"not null"`
	DependsOn  []uint    `json:"depends_on" gorm:"serializer:json"`
	Timeout    int       `json:"timeout" gorm:"default:300"` // seconds
	Retries    int       `json:"retries" gorm:"default:0"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
}

WorkflowStep represents a step in a workflow

func (WorkflowStep) TableName

func (WorkflowStep) TableName() string

TableName returns the table name for the WorkflowStep model

type WorkflowTemplate

type WorkflowTemplate struct {
	ID          uint      `json:"id" gorm:"primaryKey"`
	Name        string    `json:"name" gorm:"not null"`
	Description string    `json:"description"`
	Category    string    `json:"category"`
	Template    JSONMap   `json:"template" gorm:"type:text"`
	Public      bool      `json:"public" gorm:"default:false"`
	CreatedBy   string    `json:"created_by" gorm:"not null"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

WorkflowTemplate represents a reusable workflow template

func (WorkflowTemplate) TableName

func (WorkflowTemplate) TableName() string

TableName returns the table name for the WorkflowTemplate model

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL