task

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: MulanPSL-2.0 Imports: 16 Imported by: 0

README

#任务管理

1.主机同步任务 用户跑同步任务需要输入:账户-secretid,region,跑的任务类型(同步,创建,开启关闭等),操作的资源(主机 rbd oss等)然后task到secret数据表中查询secretkey解密,然后task将secret region参数传给provider conn获取client 然后将client 和资源类型和操作类型传给 provider 对应的服务去执行将结果传给task,task在传给host服务录入数据库 /task

2.主机创建

3.rbd同步

4.oss创建bucket

上面这种方案就不需要多个路由,一个路由对应多个实现方法,后端逻辑来处理节藕拆分

其实比较清晰的架构来写还可以这样 用户只需要传secret ID region,然后不同的路由对应不同的资源类型和操作类型,这样一个路由只对应一个方法结构更清晰 /task/host/syncs

任务的状态 状态 staring running complete 开启时间 结束时间 执行日志

  • secret
  • provider
  • host service

/task/

# 这个是资源同步的任务
type: "sync"
# secret, 比如腾讯云secret
secret_id: "xxx"
# operater 按照资源划分, 不如操作主机
resource_type: "host"
# 操作那个地域的资源
region: "shanghai"

任务的状态:

  • 状态: running
  • 开启时间
  • 介绍时间
  • 执行日志

问题1 同步任务失败接下来要怎么办? 解决办法1:简单粗暴,重新再执行一遍全部同步,因为主键id是从公有云上同步来的肯定每个实例都是唯一的,所以不担心入库的是否出现存入多个相同实例,缺点耗费时间 解决办法2:将同步失败的实例id或者记录下来,然后在同步的时候添加一个过滤器只同步这些资源

Documentation

Index

Constants

View Source
const (
	AppName = "task"
)

Variables

View Source
var (
	TaskType_name = map[int32]string{
		0: "RESOURCE_SYNC",
		1: "RESOURCE_RELEASE",
		2: "RESOURCE_CREATE",
		3: "RESOURCE_START",
		4: "RESOURCE_STOP",
	}
	TaskType_value = map[string]int32{
		"RESOURCE_SYNC":    0,
		"RESOURCE_RELEASE": 1,
		"RESOURCE_CREATE":  2,
		"RESOURCE_START":   3,
		"RESOURCE_STOP":    4,
	}
)

Enum value maps for TaskType.

View Source
var (
	Stage_name = map[int32]string{
		0: "PENDDING",
		1: "RUNNING",
		2: "SUCCESS",
		3: "FAILED",
		4: "WARNING",
	}
	Stage_value = map[string]int32{
		"PENDDING": 0,
		"RUNNING":  1,
		"SUCCESS":  2,
		"FAILED":   3,
		"WARNING":  4,
	}
)

Enum value maps for Stage.

View Source
var File_apps_task_pb_task_proto protoreflect.FileDescriptor
View Source
var Service_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "cmdb.task.Service",
	HandlerType: (*ServiceServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "CreateTask",
			Handler:    _Service_CreateTask_Handler,
		},
		{
			MethodName: "QueryBook",
			Handler:    _Service_QueryBook_Handler,
		},
		{
			MethodName: "DescribeBook",
			Handler:    _Service_DescribeBook_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "apps/task/pb/task.proto",
}

Service_ServiceDesc is the grpc.ServiceDesc for Service service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func RegisterServiceServer

func RegisterServiceServer(s grpc.ServiceRegistrar, srv ServiceServer)

Types

type CreateTaskRequst

type CreateTaskRequst struct {

	// 任务类型
	// @gotags: json:"type"
	Type TaskType `protobuf:"varint,1,opt,name=type,proto3,enum=cmdb.task.TaskType" json:"type,omitempty"`
	// 测试运行
	// @gotags: json:"dry_run"
	DryRun bool `protobuf:"varint,2,opt,name=dry_run,json=dryRun,proto3" json:"dry_run,omitempty"`
	// 任务使用的云商凭证Id
	// @gotags: json:"secret_id" validate:"required,lte=100"
	SecretId string `protobuf:"bytes,3,opt,name=secret_id,json=secretId,proto3" json:"secret_id,omitempty"`
	// 任务操作的资源类型
	// @gotags: json:"resource_type"
	ResourceType resource.Type `protobuf:"varint,4,opt,name=resource_type,json=resourceType,proto3,enum=cmdb.resource.Type" json:"resource_type,omitempty"`
	// 通知资源的Region
	// @gotags: json:"region"
	Region string `protobuf:"bytes,5,opt,name=region,proto3" json:"region,omitempty"`
	// 额外的一些参数
	// @gotags: json:"params"
	Params map[string]string `` /* 153-byte string literal not displayed */
	// 任务执行的超时时间
	// @gotags: json:"timeout"
	Timeout int64 `protobuf:"varint,7,opt,name=timeout,proto3" json:"timeout,omitempty"`
	// 任务描述
	// @gotags: json:"description"
	Descripton string `protobuf:"bytes,8,opt,name=descripton,proto3" json:"descripton,omitempty"`
	// 请求速率限制, 默认1秒30个 暂时不支持传值
	// @gotags: json:"request_rate"
	RequestRate int32 `protobuf:"varint,9,opt,name=request_rate,json=requestRate,proto3" json:"request_rate,omitempty"`
	// contains filtered or unexported fields
}

func NewCreateTaskRequest

func NewCreateTaskRequest() *CreateTaskRequst

func (*CreateTaskRequst) Descriptor deprecated

func (*CreateTaskRequst) Descriptor() ([]byte, []int)

Deprecated: Use CreateTaskRequst.ProtoReflect.Descriptor instead.

func (*CreateTaskRequst) GetDescripton

func (x *CreateTaskRequst) GetDescripton() string

func (*CreateTaskRequst) GetDryRun

func (x *CreateTaskRequst) GetDryRun() bool

func (*CreateTaskRequst) GetParams

func (x *CreateTaskRequst) GetParams() map[string]string

func (*CreateTaskRequst) GetRegion

func (x *CreateTaskRequst) GetRegion() string

func (*CreateTaskRequst) GetRequestRate

func (x *CreateTaskRequst) GetRequestRate() int32

func (*CreateTaskRequst) GetResourceType

func (x *CreateTaskRequst) GetResourceType() resource.Type

func (*CreateTaskRequst) GetSecretId

func (x *CreateTaskRequst) GetSecretId() string

func (*CreateTaskRequst) GetTimeout

func (x *CreateTaskRequst) GetTimeout() int64

func (*CreateTaskRequst) GetType

func (x *CreateTaskRequst) GetType() TaskType

func (*CreateTaskRequst) ProtoMessage

func (*CreateTaskRequst) ProtoMessage()

func (*CreateTaskRequst) ProtoReflect

func (x *CreateTaskRequst) ProtoReflect() protoreflect.Message

func (*CreateTaskRequst) Reset

func (x *CreateTaskRequst) Reset()

func (*CreateTaskRequst) String

func (x *CreateTaskRequst) String() string

func (*CreateTaskRequst) Validate

func (req *CreateTaskRequst) Validate() error

type DescribeTaskRequest

type DescribeTaskRequest struct {

	// Task id
	// @gotags: json:"id" validate:"required"
	Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	// contains filtered or unexported fields
}

func (*DescribeTaskRequest) Descriptor deprecated

func (*DescribeTaskRequest) Descriptor() ([]byte, []int)

Deprecated: Use DescribeTaskRequest.ProtoReflect.Descriptor instead.

func (*DescribeTaskRequest) GetId

func (x *DescribeTaskRequest) GetId() string

func (*DescribeTaskRequest) ProtoMessage

func (*DescribeTaskRequest) ProtoMessage()

func (*DescribeTaskRequest) ProtoReflect

func (x *DescribeTaskRequest) ProtoReflect() protoreflect.Message

func (*DescribeTaskRequest) Reset

func (x *DescribeTaskRequest) Reset()

func (*DescribeTaskRequest) String

func (x *DescribeTaskRequest) String() string

type QueryTaskRequest

type QueryTaskRequest struct {

	// 分页参数
	// @gotags: json:"page"
	Page *request.PageRequest `protobuf:"bytes,1,opt,name=page,proto3" json:"page,omitempty"`
	// 更加资源类型来过滤任务
	// @gotags: json:"resource_type"
	ResourceType resource.Type `protobuf:"varint,3,opt,name=resource_type,json=resourceType,proto3,enum=cmdb.resource.Type" json:"resource_type,omitempty"`
	// @gotags: json:"keywords"
	Keywords string `protobuf:"bytes,4,opt,name=keywords,proto3" json:"keywords,omitempty"`
	// contains filtered or unexported fields
}

func (*QueryTaskRequest) Descriptor deprecated

func (*QueryTaskRequest) Descriptor() ([]byte, []int)

Deprecated: Use QueryTaskRequest.ProtoReflect.Descriptor instead.

func (*QueryTaskRequest) GetKeywords

func (x *QueryTaskRequest) GetKeywords() string

func (*QueryTaskRequest) GetPage

func (x *QueryTaskRequest) GetPage() *request.PageRequest

func (*QueryTaskRequest) GetResourceType

func (x *QueryTaskRequest) GetResourceType() resource.Type

func (*QueryTaskRequest) ProtoMessage

func (*QueryTaskRequest) ProtoMessage()

func (*QueryTaskRequest) ProtoReflect

func (x *QueryTaskRequest) ProtoReflect() protoreflect.Message

func (*QueryTaskRequest) Reset

func (x *QueryTaskRequest) Reset()

func (*QueryTaskRequest) String

func (x *QueryTaskRequest) String() string

type ServiceClient

type ServiceClient interface {
	CreateTask(ctx context.Context, in *CreateTaskRequst, opts ...grpc.CallOption) (*Task, error)
	QueryBook(ctx context.Context, in *QueryTaskRequest, opts ...grpc.CallOption) (*TaskSet, error)
	DescribeBook(ctx context.Context, in *DescribeTaskRequest, opts ...grpc.CallOption) (*Task, error)
}

ServiceClient is the client API for Service service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewServiceClient

func NewServiceClient(cc grpc.ClientConnInterface) ServiceClient

type ServiceServer

type ServiceServer interface {
	CreateTask(context.Context, *CreateTaskRequst) (*Task, error)
	QueryBook(context.Context, *QueryTaskRequest) (*TaskSet, error)
	DescribeBook(context.Context, *DescribeTaskRequest) (*Task, error)
	// contains filtered or unexported methods
}

ServiceServer is the server API for Service service. All implementations must embed UnimplementedServiceServer for forward compatibility

type Stage

type Stage int32

任务运行的状态

const (
	Stage_PENDDING Stage = 0
	Stage_RUNNING  Stage = 1
	Stage_SUCCESS  Stage = 2
	Stage_FAILED   Stage = 3
	Stage_WARNING  Stage = 4
)

func ParseStageFromString

func ParseStageFromString(str string) (Stage, error)

ParseStageFromString Parse Stage from string

func (Stage) Descriptor

func (Stage) Descriptor() protoreflect.EnumDescriptor

func (Stage) Enum

func (x Stage) Enum() *Stage

func (Stage) EnumDescriptor deprecated

func (Stage) EnumDescriptor() ([]byte, []int)

Deprecated: Use Stage.Descriptor instead.

func (Stage) Equal

func (t Stage) Equal(target Stage) bool

Equal type compare

func (Stage) IsIn

func (t Stage) IsIn(targets ...Stage) bool

IsIn todo

func (Stage) MarshalJSON

func (t Stage) MarshalJSON() ([]byte, error)

MarshalJSON todo

func (Stage) Number

func (x Stage) Number() protoreflect.EnumNumber

func (Stage) String

func (x Stage) String() string

func (Stage) Type

func (Stage) Type() protoreflect.EnumType

func (*Stage) UnmarshalJSON

func (t *Stage) UnmarshalJSON(b []byte) error

UnmarshalJSON todo

type Status

type Status struct {

	// 任务状态
	// @gotags: json:"stage"
	Stage Stage `protobuf:"varint,1,opt,name=stage,proto3,enum=cmdb.task.Stage" json:"stage,omitempty"`
	// 失败时的异常信息
	// @gotags: json:"message"
	Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
	// 开始同步的时间
	// @gotags: json:"start_at"
	StartAt int64 `protobuf:"varint,3,opt,name=start_at,json=startAt,proto3" json:"start_at,omitempty"`
	// 同步结束时间
	// @gotags: json:"end_at"
	EndAt int64 `protobuf:"varint,4,opt,name=end_at,json=endAt,proto3" json:"end_at,omitempty"`
	// 成功的条数
	// @gotags: json:"total_succeed"
	TotalSucceed int64 `protobuf:"varint,5,opt,name=total_succeed,json=totalSucceed,proto3" json:"total_succeed,omitempty"`
	// 失败的条数
	// @gotags: json:"total_failed"
	TotalFailed int64 `protobuf:"varint,6,opt,name=total_failed,json=totalFailed,proto3" json:"total_failed,omitempty"`
	// contains filtered or unexported fields
}

func (*Status) Descriptor deprecated

func (*Status) Descriptor() ([]byte, []int)

Deprecated: Use Status.ProtoReflect.Descriptor instead.

func (*Status) GetEndAt

func (x *Status) GetEndAt() int64

func (*Status) GetMessage

func (x *Status) GetMessage() string

func (*Status) GetStage

func (x *Status) GetStage() Stage

func (*Status) GetStartAt

func (x *Status) GetStartAt() int64

func (*Status) GetTotalFailed

func (x *Status) GetTotalFailed() int64

func (*Status) GetTotalSucceed

func (x *Status) GetTotalSucceed() int64

func (*Status) ProtoMessage

func (*Status) ProtoMessage()

func (*Status) ProtoReflect

func (x *Status) ProtoReflect() protoreflect.Message

func (*Status) Reset

func (x *Status) Reset()

func (*Status) String

func (x *Status) String() string

type Task

type Task struct {

	// 任务id
	// @gotags: json:"id"
	Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	// 任务描述
	// @gotags: json:"data"
	Data *CreateTaskRequst `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
	// 任务状态
	// @gotags: json:"status"
	Status *Status `protobuf:"bytes,3,opt,name=status,proto3" json:"status,omitempty"`
	// contains filtered or unexported fields
}

Task 同个区域的同一种资源一次只能有1个task run

func NewDefaultTask

func NewDefaultTask() *Task

func NewTask

func NewTask(req *CreateTaskRequst) (*Task, error)

func (*Task) Descriptor deprecated

func (*Task) Descriptor() ([]byte, []int)

Deprecated: Use Task.ProtoReflect.Descriptor instead.

func (*Task) Failed

func (s *Task) Failed(message string)

func (*Task) GetData

func (x *Task) GetData() *CreateTaskRequst

func (*Task) GetId

func (x *Task) GetId() string

func (*Task) GetStatus

func (x *Task) GetStatus() *Status

func (*Task) ProtoMessage

func (*Task) ProtoMessage()

func (*Task) ProtoReflect

func (x *Task) ProtoReflect() protoreflect.Message

func (*Task) Reset

func (x *Task) Reset()

func (*Task) Run

func (s *Task) Run()

func (*Task) String

func (x *Task) String() string

func (*Task) Success

func (s *Task) Success()

type TaskSet

type TaskSet struct {

	// @gotags: json:"total"
	Total int64 `protobuf:"varint,1,opt,name=total,proto3" json:"total,omitempty"`
	// @gotags: json:"items"
	Items []*Task `protobuf:"bytes,2,rep,name=items,proto3" json:"items,omitempty"`
	// contains filtered or unexported fields
}

func (*TaskSet) Descriptor deprecated

func (*TaskSet) Descriptor() ([]byte, []int)

Deprecated: Use TaskSet.ProtoReflect.Descriptor instead.

func (*TaskSet) GetItems

func (x *TaskSet) GetItems() []*Task

func (*TaskSet) GetTotal

func (x *TaskSet) GetTotal() int64

func (*TaskSet) ProtoMessage

func (*TaskSet) ProtoMessage()

func (*TaskSet) ProtoReflect

func (x *TaskSet) ProtoReflect() protoreflect.Message

func (*TaskSet) Reset

func (x *TaskSet) Reset()

func (*TaskSet) String

func (x *TaskSet) String() string

type TaskType

type TaskType int32

任务类型

const (
	// 资源同步任务
	TaskType_RESOURCE_SYNC TaskType = 0
	// 资源释放任务
	TaskType_RESOURCE_RELEASE TaskType = 1
	TaskType_RESOURCE_CREATE  TaskType = 2
	TaskType_RESOURCE_START   TaskType = 3
	TaskType_RESOURCE_STOP    TaskType = 4
)

func ParseTaskTypeFromString

func ParseTaskTypeFromString(str string) (TaskType, error)

ParseTaskTypeFromString Parse TaskType from string

func (TaskType) Descriptor

func (TaskType) Descriptor() protoreflect.EnumDescriptor

func (TaskType) Enum

func (x TaskType) Enum() *TaskType

func (TaskType) EnumDescriptor deprecated

func (TaskType) EnumDescriptor() ([]byte, []int)

Deprecated: Use TaskType.Descriptor instead.

func (TaskType) Equal

func (t TaskType) Equal(target TaskType) bool

Equal type compare

func (TaskType) IsIn

func (t TaskType) IsIn(targets ...TaskType) bool

IsIn todo

func (TaskType) MarshalJSON

func (t TaskType) MarshalJSON() ([]byte, error)

MarshalJSON todo

func (TaskType) Number

func (x TaskType) Number() protoreflect.EnumNumber

func (TaskType) String

func (x TaskType) String() string

func (TaskType) Type

func (*TaskType) UnmarshalJSON

func (t *TaskType) UnmarshalJSON(b []byte) error

UnmarshalJSON todo

type UnimplementedServiceServer

type UnimplementedServiceServer struct {
}

UnimplementedServiceServer must be embedded to have forward compatible implementations.

func (UnimplementedServiceServer) CreateTask

func (UnimplementedServiceServer) DescribeBook

func (UnimplementedServiceServer) QueryBook

type UnsafeServiceServer

type UnsafeServiceServer interface {
	// contains filtered or unexported methods
}

UnsafeServiceServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to ServiceServer will result in compilation errors.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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