job

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APP_NAME = "job"
)
View Source
const (
	TASK_JOB_KEY = "job_id"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateJobRequest

type CreateJobRequest struct {
	// 所属域
	Domain string `json:"domain" gorm:"column:domain" validate:"required"`
	// 所属空间
	Namespace string `json:"namespace" gorm:"column:namespace" validate:"required"`
	// 创建人
	CreateBy string `json:"create_by" gorm:"column:create_by"`
	// job定义
	CreateJobSpec
}

func NewCreateJobRequest

func NewCreateJobRequest() *CreateJobRequest

func (*CreateJobRequest) SetCreateBy

func (r *CreateJobRequest) SetCreateBy(createBy string) *CreateJobRequest

func (*CreateJobRequest) SetDescription

func (r *CreateJobRequest) SetDescription(description string) *CreateJobRequest

func (*CreateJobRequest) SetInputParam

func (r *CreateJobRequest) SetInputParam(reqs ...*RunParam) *CreateJobRequest

func (*CreateJobRequest) SetK8sJobRunTemplate

func (r *CreateJobRequest) SetK8sJobRunTemplate(template string) *CreateJobRequest

func (*CreateJobRequest) SetLabel

func (r *CreateJobRequest) SetLabel(key, value string) *CreateJobRequest

func (*CreateJobRequest) SetName

func (r *CreateJobRequest) SetName(name string) *CreateJobRequest

func (*CreateJobRequest) SetOutputParam

func (r *CreateJobRequest) SetOutputParam(reqs ...*RunParam) *CreateJobRequest

func (*CreateJobRequest) SetParamEnumOptions

func (r *CreateJobRequest) SetParamEnumOptions(key string, options []*EnumOption) *CreateJobRequest

func (*CreateJobRequest) SetParamLabel

func (r *CreateJobRequest) SetParamLabel(key, value string) *CreateJobRequest

func (*CreateJobRequest) Validate

func (r *CreateJobRequest) Validate() error

type CreateJobSpec

type CreateJobSpec struct {
	// 执行器类型, 默认采用k8s job执行
	RunnerType task.TYPE `json:"runner_type" gorm:"column:runner_type;type:varchar(32)" validate:"required"`
	// 执行器定义, 比如 k8s job 定义中的 &corev1.PodSpec{}, 是YAML模版
	RunTemplate string `json:"run_template" gorm:"column:run_template;type:text"`
	// 运行时 用户传人的参数说明
	InputParams []*RunParam `json:"input_params" gorm:"column:input_params;serializer:json;type:json"`
	// 运行时 用户传人的参数说明
	OutputParams []*RunParam `json:"output_params" gorm:"column:output_params;serializer:json;type:json"`
	Logo string `json:"logo" gorm:"column:logo"`
	// 图标
	Icon string `json:"icon" gorm:"column:icon"`
	// 名称, 不能包含特殊字符(. , #)
	Name string `json:"name" validate:"required" gorm:"column:name;type:varchar(128)"`
	// 展示名称
	DisplayName string `json:"display_name" gorm:"column:display_name;type:varchar(128)"`
	// 是否是公开Job, 默认只能本空间内访问
	VisiableMode resource.VISIABLE `json:"visiable_mode" gorm:"column:visiable_mode;type:int"`
	// 描述, Job功能概述
	Description string `json:"description" gorm:"column:description;type:text"`
	// Job 的Readme说明文档, 支持Markdown格式
	Readme string `json:"readme" gorm:"column:readme;type:text"`
	// 文档的URL地址
	DocumentUrl string `json:"document_url" gorm:"column:document_url;type:varchar(512)"`
	// 标签
	Labels map[string]string `json:"labels" gorm:"column:labels;serializer:json;type:json"`
	// 扩展属性
	Extension map[string]string `json:"extension" gorm:"column:extension;serializer:json;type:json"`
}

func NewCreateJobSpec

func NewCreateJobSpec() *CreateJobSpec

func (*CreateJobSpec) GetMatchedInputParamsByLabel

func (r *CreateJobSpec) GetMatchedInputParamsByLabel(key, valut string) []*RunParam

type DeleteJobRequest

type DeleteJobRequest struct {
	DescribeJobRequest
}

func NewDeleteJobRequest

func NewDeleteJobRequest(idOrName string) *DeleteJobRequest

type DescribeJobRequest

type DescribeJobRequest struct {
	JobIdOrName string `json:"id_or_name"`
}

func NewDescribeJobRequest

func NewDescribeJobRequest(idOrName string) *DescribeJobRequest

type EnumOption

type EnumOption struct {
	// 选项的说明
	Label string `json:"label"`
	// 选项的值
	Value string `json:"value" validate:"required"`
	// 扩展属性
	Extensions map[string]string `json:"extensions"`
}

type HttpEnumConfig

type HttpEnumConfig struct {
	// 基于枚举的URL, 注意只支持Get方法
	Url string `json:"url"`
	// Enum Label映射的字段名
	EnumLabelName string `json:"enum_label_name"`
	// Enum Value映射的字段名
	EnumLabelValue string `json:"enum_label_value"`
}

type JOB_STAGE

type JOB_STAGE string
const (
	// draft 草案, 未发布状态, 允许编辑
	JOB_STAGE_DRAFT JOB_STAGE = "draft"
	// published 已发布, 已发布的job不允许修改
	JOB_STAGE_PUBLISHED JOB_STAGE = "published"
	// deprecated 已废弃, 已废弃的Job不允许再被使用
	JOB_STAGE_DEPRECATED JOB_STAGE = "deprecated"
)

type Job

type Job struct {
	// 对象Id
	Id string `json:"id" gorm:"column:id;primaryKey"`
	// 创建时间
	CreateAt time.Time `json:"create_at" gorm:"column:create_at"`
	// 更新时间
	UpdateAt *time.Time `json:"update_at" gorm:"column:update_at"`
	// 更新人
	UpdateBy string `json:"update_by" gorm:"column:update_by;type:varchar(60)"`

	// Job定义
	CreateJobRequest
	// Job状态
	JobStatus
}

func NewJob

func NewJob(spec CreateJobRequest) *Job

func (*Job) String

func (r *Job) String() string

func (*Job) TableName

func (r *Job) TableName() string

type JobStatus

type JobStatus struct {
	// job创建信息
	Stage JOB_STAGE `json:"stage" gorm:"column:stage;type:varchar(32)"`
	// 发布的版本
	Version string `json:"version" validate:"required" gorm:"column:version;type:varchar(64)"`
	// 发布时间
	ChangeAt int64 `json:"change_at" gorm:"column:change_at"`
	// 发布人
	ChangeBy string `json:"change_by" gorm:"column:change_by;type:varchar(60)"`
	// 发布描述
	ChangeDescribe string `json:"change_describe" gorm:"column:change_describe;type:text"`
}

func NewJobStatus

func NewJobStatus() *JobStatus

type PARAM_USAGE_TYPE

type PARAM_USAGE_TYPE string
const (
	// 环境变量
	PARAM_USAGE_TYPE_ENV PARAM_USAGE_TYPE = "env"
	// 模版变量
	PARAM_USAGE_TYPE_TEMPLATE PARAM_USAGE_TYPE = "template"
	// 执行器变量
	PARAM_USAGE_TYPE_RUNNER PARAM_USAGE_TYPE = "runner"
	// 系统内部参数, 有系统自动注入
	PARAM_USAGE_TYPE_SYSTEM PARAM_USAGE_TYPE = "system"
)

type PARAM_VALUE_TYPE

type PARAM_VALUE_TYPE string
const (
	// 文本
	PARAM_VALUE_TYPE_TEXT PARAM_VALUE_TYPE = "text"
	// 布尔值, 只能是ture或者false
	PARAM_VALUE_TYPE_BOOLEAN PARAM_VALUE_TYPE = "boolean"
	// 枚举
	PARAM_VALUE_TYPE_ENUM PARAM_VALUE_TYPE = "enum"
	// 基于url的远程选项拉去, 仅存储URL地址, 前端自己处理
	PARAM_VALUE_TYPE_HTTP_ENUM PARAM_VALUE_TYPE = "http-enum"
	// k8s的 secret 名称
	PARAM_VALUE_TYPE_K8S_CONFIG_MAP PARAM_VALUE_TYPE = "k8s-configmap"
	// k8s的 config map 名称
	PARAM_VALUE_TYPE_K8S_SECRET PARAM_VALUE_TYPE = "k8s-secret"
)

type QueryJobRequest

type QueryJobRequest struct {
	request.PageRequest
}

func NewQueryJobRequest

func NewQueryJobRequest() *QueryJobRequest

type RunJobRequest

type RunJobRequest struct {
	// 任务名称
	TaskName string `json:"task_name" gorm:"column:task_name" validate:"required"`
	// 任务描述
	Description string `json:"description"  gorm:"column:description"`
	// Job名称
	JobName string `json:"job_name" gorm:"job_name" validate:"required"`
	// 设置 Job 失败时的重试次数
	MaxRetry *int32 `json:"max_retry" gorm:"column:max_retry"`
	// 设置 Job 的存活时间(秒),完成后 300 秒自动删除
	TTLSecondsAfterFinished *int32 `json:"ttl_seconds_after_finished" gorm:"column:ttl_seconds_after_finished"`
	// 试运行
	DryRun *bool `json:"dry_run" gorm:"column:dry_run"`
	// 执行器的名称
	RunnerName string `json:"runner_name" gorm:"column:runner_name" validate:"required"`
	// 运行时参数
	RunParams []RunParam `json:"run_params" gorm:"column:run_params"`
	// 标签
	Label map[string]string `json:"label" gorm:"column:label"`
}

func NewRunJobRequest

func NewRunJobRequest() *RunJobRequest

func (*RunJobRequest) AddRunParam

func (r *RunJobRequest) AddRunParam(params ...*RunParam) *RunJobRequest

func (*RunJobRequest) SetDescription

func (r *RunJobRequest) SetDescription(description string) *RunJobRequest

func (*RunJobRequest) SetDryRun

func (r *RunJobRequest) SetDryRun(dryRun bool) *RunJobRequest

func (*RunJobRequest) SetJobName

func (r *RunJobRequest) SetJobName(jobName string) *RunJobRequest

func (*RunJobRequest) SetLabel

func (r *RunJobRequest) SetLabel(key, value string) *RunJobRequest

func (*RunJobRequest) SetRunnerName

func (r *RunJobRequest) SetRunnerName(rinnerName string) *RunJobRequest

func (*RunJobRequest) SetTaskName

func (r *RunJobRequest) SetTaskName(taskName string) *RunJobRequest

func (*RunJobRequest) Validate

func (r *RunJobRequest) Validate() error

type RunParam

type RunParam struct {
	// 可选/必传
	Required bool `json:"required"`
	// 参数使用类型
	UsageType PARAM_USAGE_TYPE `json:"usage_type"`
	// 参数名称
	Name string `json:"name" validate:"required"`
	// 设置了值后,不允许修改, 用于控制流水线模版变量
	ReadOnly bool `json:"read_only"`
	// 参数描述
	NameDesc string `json:"name_desc"`
	// 值类型
	ValueType PARAM_VALUE_TYPE `json:"value_type"`
	// 枚举值的选项
	EnumOptions []*EnumOption `json:"enum_options"`
	// 基于Http枚举的配置
	HttpEnumConfig *HttpEnumConfig `json:"http_enum_config"`
	// 值的样例
	Example string `json:"example"`
	// 默认值, task运行时如果未传人,会填充默认值
	Value string `json:"value"`
	// 有事件触发时 自动注入
	EventInject bool `json:"event_inject"`
	// 值描述
	ValueDesc string `json:"value_desc"`
	// 是否加入到过滤标签中, 方便过滤搜索, 默认不会加入到搜索标签中
	SearchLabel bool `json:"search_label"`
	// 是否是敏感信息, 比如密码之类的, 如果是,显示的时候需要做脱敏处理
	IsSensitive bool `json:"is_sensitive"`
	// 是否废弃
	Deprecate bool `json:"deprecate"`
	// 废弃说明
	DeprecateDesc string `json:"deprecate_desc"`
	// 参数标签
	Lable map[string]string `json:"label"`
	// 扩展属性
	Extensions map[string]string `json:"extensions"`
}

func (*RunParam) IsMatchLabel

func (r *RunParam) IsMatchLabel(key, valut string) bool

func (*RunParam) SetLabel

func (r *RunParam) SetLabel(key, value string) *RunParam

type Service

type Service interface {
	// 创建Job
	CreateJob(context.Context, *CreateJobRequest) (*Job, error)
	// 查询Job
	QueryJob(context.Context, *QueryJobRequest) (*types.Set[*Job], error)
	// 获取Job详情
	DescribeJob(context.Context, *DescribeJobRequest) (*Job, error)
	// 删除Job
	DeleteJob(context.Context, *DeleteJobRequest) (*Job, error)
}

func GetService

func GetService() Service

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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