executor

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExecutorNotFound   = errors.New("executor not found for task type")
	ErrExecutionTimeout   = errors.New("task execution timeout")
	ErrMaxRetriesExceeded = errors.New("max retries exceeded")
)

Functions

This section is empty.

Types

type DefaultExecutorFactory

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

DefaultExecutorFactory 默认执行器工厂

func (*DefaultExecutorFactory) GetExecutor

func (f *DefaultExecutorFactory) GetExecutor(taskType domain.TaskType) (Executor, error)

GetExecutor 获取执行器

func (*DefaultExecutorFactory) RegisterExecutor

func (f *DefaultExecutorFactory) RegisterExecutor(executor Executor)

RegisterExecutor 注册执行器

func (*DefaultExecutorFactory) ValidateTask

func (f *DefaultExecutorFactory) ValidateTask(ctx context.Context, job domain.CronJob) error

ValidateTask 校验任务配置

type ExecutionResult

type ExecutionResult struct {
	Success   bool        `json:"success"`
	Message   string      `json:"message"`
	Data      interface{} `json:"data,omitempty"`
	StartTime int64       `json:"start_time"`
	EndTime   int64       `json:"end_time"`
	Duration  int64       `json:"duration"` // 毫秒
}

ExecutionResult 任务执行结果

type Executor

type Executor interface {
	// Execute 执行任务
	Execute(ctx context.Context, job domain.CronJob) (*ExecutionResult, error)

	// Validate 校验任务配置是否有效(创建任务时调用)
	Validate(ctx context.Context, job domain.CronJob) error

	// Type 返回执行器类型
	Type() domain.TaskType
}

Executor 任务执行器接口

type ExecutorFactory

type ExecutorFactory interface {
	// GetExecutor 根据任务类型获取执行器
	GetExecutor(taskType domain.TaskType) (Executor, error)
	// ValidateTask 校验任务配置是否有效
	ValidateTask(ctx context.Context, job domain.CronJob) error
}

ExecutorFactory 执行器工厂

func NewExecutorFactory

func NewExecutorFactory(l logx.Loggerx) ExecutorFactory

NewExecutorFactory 创建执行器工厂

func NewExecutorFactoryWithHistory

func NewExecutorFactoryWithHistory(historyService service.JobHistoryService, l logx.Loggerx) ExecutorFactory

NewExecutorFactoryWithHistory 创建带历史记录的执行器工厂

type FunctionExecutor

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

FunctionExecutor Function类型任务执行器

func NewFunctionExecutor

func NewFunctionExecutor(l logx.Loggerx) *FunctionExecutor

NewFunctionExecutor 创建Function执行器

func (*FunctionExecutor) Execute

Execute 执行Function任务

func (*FunctionExecutor) HasFunction

func (f *FunctionExecutor) HasFunction(name string) bool

HasFunction 检查函数是否已注册

func (*FunctionExecutor) ListFunctions

func (f *FunctionExecutor) ListFunctions() []string

ListFunctions 列出所有已注册的函数名

func (*FunctionExecutor) RegisterFunction

func (f *FunctionExecutor) RegisterFunction(name string, fn func(context.Context, map[string]interface{}) (interface{}, error))

RegisterFunction 注册函数

func (*FunctionExecutor) Type

func (f *FunctionExecutor) Type() domain.TaskType

Type 返回执行器类型

func (*FunctionExecutor) Validate

func (f *FunctionExecutor) Validate(ctx context.Context, job domain.CronJob) error

Validate 校验Function任务配置

type GRPCExecutor

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

GRPCExecutor gRPC任务执行器

func NewGRPCExecutor

func NewGRPCExecutor(l logx.Loggerx) *GRPCExecutor

NewGRPCExecutor 创建gRPC执行器

func (*GRPCExecutor) Execute

func (g *GRPCExecutor) Execute(ctx context.Context, job domain.CronJob) (*ExecutionResult, error)

Execute 执行gRPC任务

func (*GRPCExecutor) Type

func (g *GRPCExecutor) Type() domain.TaskType

Type 返回执行器类型

func (*GRPCExecutor) Validate

func (g *GRPCExecutor) Validate(ctx context.Context, job domain.CronJob) error

Validate 校验gRPC任务配置

type GRPCTaskConfig

type GRPCTaskConfig struct {
	Target      string            `json:"target"`       // gRPC服务地址,如 "localhost:50051"
	Service     string            `json:"service"`      // 服务名,如 "helloworld.Greeter"
	Method      string            `json:"method"`       // 方法名,如 "SayHello"
	RequestData string            `json:"request_data"` // 请求数据(JSON格式)
	Metadata    map[string]string `json:"metadata"`     // gRPC元数据
}

GRPCTaskConfig gRPC任务配置

type HTTPExecutor

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

HTTPExecutor HTTP任务执行器

func NewHTTPExecutor

func NewHTTPExecutor(l logx.Loggerx) *HTTPExecutor

NewHTTPExecutor 创建HTTP执行器

func (*HTTPExecutor) Execute

func (h *HTTPExecutor) Execute(ctx context.Context, job domain.CronJob) (*ExecutionResult, error)

Execute 执行HTTP任务

func (*HTTPExecutor) Type

func (h *HTTPExecutor) Type() domain.TaskType

Type 返回执行器类型

func (*HTTPExecutor) Validate

func (h *HTTPExecutor) Validate(ctx context.Context, job domain.CronJob) error

Validate 校验HTTP任务配置

type HTTPTaskConfig

type HTTPTaskConfig struct {
	URL     string            `json:"url"`
	Method  string            `json:"method"` // GET, POST, PUT, DELETE
	Headers map[string]string `json:"headers"`
	Body    string            `json:"body"`
}

HTTPTaskConfig HTTP任务配置(存储在CronJob的额外字段中)

type HistoryRecordingExecutor

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

HistoryRecordingExecutor 带历史记录功能的执行器包装器

func NewHistoryRecordingExecutor

func NewHistoryRecordingExecutor(executor Executor, historyService service.JobHistoryService, l logx.Loggerx) *HistoryRecordingExecutor

NewHistoryRecordingExecutor 创建带历史记录的执行器

func (*HistoryRecordingExecutor) Execute

Execute 执行任务并记录历史

func (*HistoryRecordingExecutor) Type

Type 返回执行器类型

func (*HistoryRecordingExecutor) Validate

Validate 代理到内部执行器的校验

type RetryableExecutor

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

RetryableExecutor 带重试机制的执行器包装器

func NewRetryableExecutor

func NewRetryableExecutor(executor Executor, l logx.Loggerx) *RetryableExecutor

NewRetryableExecutor 创建带重试的执行器

func (*RetryableExecutor) Execute

Execute 执行任务(带重试)

func (*RetryableExecutor) Type

func (r *RetryableExecutor) Type() domain.TaskType

Type 返回执行器类型

func (*RetryableExecutor) Validate

func (r *RetryableExecutor) Validate(ctx context.Context, job domain.CronJob) error

Validate 代理到内部执行器的校验

type RetryableHistoryExecutor

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

RetryableHistoryExecutor 带重试和历史记录的执行器包装器

func NewRetryableHistoryExecutor

func NewRetryableHistoryExecutor(executor Executor, historyService service.JobHistoryService, l logx.Loggerx) *RetryableHistoryExecutor

NewRetryableHistoryExecutor 创建带重试和历史记录的执行器

func (*RetryableHistoryExecutor) Execute

Execute 执行任务(带重试和历史记录)

func (*RetryableHistoryExecutor) Type

Type 返回执行器类型

func (*RetryableHistoryExecutor) Validate

Validate 代理到内部执行器的校验

Jump to

Keyboard shortcuts

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