task

package
v0.0.0-...-0f35d45 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeCopyDir uint32 = iota + 1
	TypeCopyFile
	TypeCopySingleFile
	TypeCopyMultipartFile
	TypeCopyMultipart
)
View Source
const (
	JobStatusSucceed uint32 = iota
	JobStatusFailed
)

Variables

This section is empty.

Functions

func HandleAsLeader

func HandleAsLeader(ctx context.Context, addr, subject string, workerIds []string, job *proto.Job) (err error)

func HandleAsWorker

func HandleAsWorker(ctx context.Context, addr, subject string, storages []types.Storager) (err error)

func SubjectClockin

func SubjectClockin(subject string) string

subject is the ElectReply.Subject

func SubjectClockout

func SubjectClockout(subject string) string

subject is the ElectReply.Subject

func SubjectClockoutNotify

func SubjectClockoutNotify(subject string) string

subject is the ElectReply.Subject

func SubjectJobReply

func SubjectJobReply(jobId string) string

JobReply subject will be holding on Staff. Staff will use this subject to wait for replies on specific job.

func SubjectTask

func SubjectTask(taskId string) string

Task subject will be holding on Staff. All staff (both leader and worker) will use this subject to publish new jobs.

func SubjectTaskReply

func SubjectTaskReply(taskId string) string

TaskReply subject will be holding on Manager.

func SubjectTasks

func SubjectTasks() string

Tasks subject will be holding on Manager. Manager use this subject to publish new tasks.

Types

type Leader

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

func NewLeader

func NewLeader(ctx context.Context, addr, subject string, workerIds []string) (l *Leader, err error)

func (*Leader) Handle

func (l *Leader) Handle(ctx context.Context, job *proto.Job) (err error)

type Manager

type Manager struct {
	proto.UnimplementedStaffServer
	// contains filtered or unexported fields
}

func NewManager

func NewManager(ctx context.Context, cfg ManagerConfig) (p *Manager, err error)

func (*Manager) Elect

func (p *Manager) Elect(ctx context.Context, request *proto.ElectRequest) (*proto.ElectReply, error)

func (*Manager) Publish

func (p *Manager) Publish(ctx context.Context, task *proto.Task) (err error)

Publish will publish a task on "tasks" queue.

func (*Manager) Register

func (p *Manager) Register(ctx context.Context, request *proto.RegisterRequest) (*proto.RegisterReply, error)

func (*Manager) Wait

func (p *Manager) Wait(ctx context.Context, task *proto.Task) (err error)

Wait will wait for all staffAddrs' replies on specific task.

type ManagerConfig

type ManagerConfig struct {
	Host     string
	GrpcPort int

	// Queue related config.
	QueuePort int
}

func (ManagerConfig) GrpcAddr

func (p ManagerConfig) GrpcAddr() string

func (ManagerConfig) QueueAddr

func (p ManagerConfig) QueueAddr() string

type Runner

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

func NewRunner

func NewRunner(a *Worker, j *proto.Job) (*Runner, error)

func (*Runner) Async

func (rn *Runner) Async(ctx context.Context, job *proto.Job) (err error)

func (*Runner) Await

func (rn *Runner) Await(ctx context.Context) (err error)

func (*Runner) Finish

func (rn *Runner) Finish(ctx context.Context, reply string, err error) error

func (*Runner) Handle

func (rn *Runner) Handle(reply string)

func (*Runner) HandleCopyDir

func (rn *Runner) HandleCopyDir(ctx context.Context, msg protobuf.Message) error

func (*Runner) HandleCopyFile

func (rn *Runner) HandleCopyFile(ctx context.Context, msg protobuf.Message) error

func (*Runner) HandleCopyMultipart

func (rn *Runner) HandleCopyMultipart(ctx context.Context, msg protobuf.Message) error

func (*Runner) HandleCopyMultipartFile

func (rn *Runner) HandleCopyMultipartFile(ctx context.Context, msg protobuf.Message) error

func (*Runner) HandleCopySingleFile

func (rn *Runner) HandleCopySingleFile(ctx context.Context, msg protobuf.Message) error

func (*Runner) Sync

func (rn *Runner) Sync(ctx context.Context, job *proto.Job) (err error)

type Staff

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

func NewStaff

func NewStaff(ctx context.Context, cfg StaffConfig) (s *Staff, err error)

func (*Staff) Connect

func (s *Staff) Connect(ctx context.Context) (err error)

Connect will connect to portal task queue.

func (*Staff) Handle

func (s *Staff) Handle(reply string, task *proto.Task)

Handle will create a new agent to handle task.

type StaffConfig

type StaffConfig struct {
	Host string

	ManagerAddr string
}

type Worker

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

func NewWorker

func NewWorker(ctx context.Context, addr, subject string, storages []types.Storager) (*Worker, error)

func (*Worker) Handle

func (w *Worker) Handle(ctx context.Context) (err error)

Jump to

Keyboard shortcuts

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