task

package
v0.0.0-...-62da3de Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

基于ssh方式远程执行命令

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(app *eudore.Eudore) error

task

trigger scheduler executor

Types

type AgentConfig

type AgentConfig struct {
	Name  string `json:"name,omitempty"`
	Addr  string `json:"addr"`
	Uri   string `json:"uri"`
	Toekn string `json:"token"`
}

func (*AgentConfig) EncodeConfig

func (ac *AgentConfig) EncodeConfig() string

type AgentExecutor

type AgentExecutor struct {
	Addr  string `json:"addr"`
	Uri   string `json:"uri"`
	Toekn string `json:"token"`
	// contains filtered or unexported fields
}

func NewAgentExecutor

func NewAgentExecutor(config string) *AgentExecutor

func (*AgentExecutor) Run

func (exec *AgentExecutor) Run(task *Task) error

type CronTrigger

type CronTrigger struct {
	Cron     *cron.Cron
	Schedule chan *Event
	EventIds map[int]cron.EntryID
}

func NewCronTrigger

func NewCronTrigger(sc chan *Event) *CronTrigger

func (*CronTrigger) AddEntry

func (tg *CronTrigger) AddEntry(i map[string]interface{}) error

type CycleTrigger

type CycleTrigger struct {
	Node     *cycleNode
	Schedule chan int
}

type Event

type Event struct {
	Id          int
	Name        string
	Description string
	Params      map[string]interface{}
	ExecutorId  int
}

Event 定义静态事件

func NewEvent

func NewEvent(data map[string]interface{}) *Event

type Executor

type Executor interface {
	Run(*Task) error
}

PostgreSQL Begin CREATE SEQUENCE seq_task_executor_id INCREMENT by 1 MINVALUE 1 START 1; CREATE TABLE tb_task_executor(

"id" INTEGER PRIMARY KEY DEFAULT nextval('seq_task_executor_id'),
"name" VARCHAR(64),
"description" VARCHAR(512),
"type" VARCHAR(64),
"config" VARCHAR(512),
"time" TIMESTAMP  DEFAULT (now())

);

PostgreSQL End

func NewHttpExecutor

func NewHttpExecutor() Executor

type ExecutorController

type ExecutorController struct {
	controller.ControllerWebsite
}

PostgreSQL Begin CREATE SEQUENCE seq_task_executor_id INCREMENT by 1 MINVALUE 1 START 1; CREATE TABLE tb_task_executor(

"id" INTEGER PRIMARY KEY DEFAULT nextval('seq_task_executor_id'),
"name" VARCHAR(64),
"description" VARCHAR(512),
"type" VARCHAR(64),
"config" VARCHAR(512),
"time" TIMESTAMP  DEFAULT (now())

);

PostgreSQL End

func NewExecutorController

func NewExecutorController(db *sql.DB) *ExecutorController

func (*ExecutorController) GetCount

func (ctl *ExecutorController) GetCount() interface{}

func (*ExecutorController) GetIndex

func (ctl *ExecutorController) GetIndex() (interface{}, error)

func (*ExecutorController) GetInfoIdById

func (ctl *ExecutorController) GetInfoIdById() (interface{}, error)

func (*ExecutorController) GetInfoNameByName

func (ctl *ExecutorController) GetInfoNameByName() (interface{}, error)

func (*ExecutorController) GetList

func (ctl *ExecutorController) GetList() (interface{}, error)

func (*ExecutorController) PutAgentRegister

func (ctl *ExecutorController) PutAgentRegister()

type HttpExecutor

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

func (*HttpExecutor) Run

func (exec *HttpExecutor) Run(task *Task) error

type HttpTrigger

type HttpTrigger struct {
	Event chan *Event
	// contains filtered or unexported fields
}

func NewHttpTrigger

func NewHttpTrigger(sc chan *Event) *HttpTrigger

func (*HttpTrigger) AddEntry

func (tg *HttpTrigger) AddEntry(i map[string]interface{}) error

func (*HttpTrigger) Handle

func (tg *HttpTrigger) Handle(ctx eudore.Context)

type SSHExecutor

type SSHExecutor struct{}

func (*SSHExecutor) Run

func (exec *SSHExecutor) Run(ctx context.Context) error

type ScheduleController

type ScheduleController struct {
	controller.ControllerWebsite
	Context   context.Context
	Logger    eudore.Logger
	Name      *string
	Event     chan *Event
	Triggers  map[string]Trigger
	Executors map[int]Executor
}
func (sc *Scheduler) execute(id int) {
	ctx, cancel := context.WithTimeout(sc.ctx, 30*time.Second)
	defer cancel()
	task, ok := sc.tasks[id]
	if !ok {
		sc.Errorf("executer taskid %d not found", id)
		return
	}
	executer, ok := sc.executers[task.executer]
	if !ok {
		sc.Errorf("executer executerid %d not found", task.executer)
		return
	}
	err := executer.Run(context.WithValue(ctx, "params", task.params))
	if err != nil {
		sc.Errorf("executer %d fatal error: %v,params: %v", task.id, err, task.params)
	} else {
		sc.Infof("executer %d succss", task.id)
	}
}

func NewScheduleController

func NewScheduleController(app *eudore.App, db *sql.DB) *ScheduleController

func (*ScheduleController) ControllerRoute

func (ctl *ScheduleController) ControllerRoute() map[string]string

ControllerRoute 方法返回默认路由信息。

func (*ScheduleController) InitExecutors

func (ctl *ScheduleController) InitExecutors() error

func (*ScheduleController) InitTriggers

func (ctl *ScheduleController) InitTriggers() error

func (*ScheduleController) Inject

func (ctl *ScheduleController) Inject(controller eudore.Controller, router eudore.RouterMethod) error

Inject 方法实现控制器注入到路由器的方法,调用ControllerBaseInject方法注入。

func (*ScheduleController) PostById

func (ctl *ScheduleController) PostById()

func (*ScheduleController) PutNewTask

func (ctl *ScheduleController) PutNewTask()

func (*ScheduleController) Run

func (ctl *ScheduleController) Run()

type SshExecutor

type SshExecutor struct {
	Ip   string
	User string
	Cert string //password or key file path
	Port int
	// contains filtered or unexported fields
}

type Task

type Task struct {
	Event
	Context   context.Context
	Starttime time.Time
	Endtime   time.Time
	Err       error
	Message   []byte
}

Task 定义运行的一个任务

type TaskController

type TaskController struct {
	controller.ControllerWebsite
}

func NewTaskController

func NewTaskController(db *sql.DB) *TaskController

func (*TaskController) GetCount

func (ctl *TaskController) GetCount() interface{}

func (*TaskController) GetIndex

func (ctl *TaskController) GetIndex() (interface{}, error)

func (*TaskController) GetInfoEventIdById

func (ctl *TaskController) GetInfoEventIdById() (interface{}, error)

func (*TaskController) GetInfoExecutorById

func (ctl *TaskController) GetInfoExecutorById() (interface{}, error)

func (*TaskController) GetList

func (ctl *TaskController) GetList() (interface{}, error)

type Trigger

type Trigger interface {
	AddEntry(map[string]interface{}) error
}

PostgreSQL Begin -- task触发器 CREATE SEQUENCE seq_task_trigger_id INCREMENT by 1 MINVALUE 1 START 1; CREATE TABLE tb_task_trigger(

"id" INTEGER PRIMARY KEY DEFAULT nextval('seq_task_trigger_id'),
"name" VARCHAR(64),
"description" VARCHAR(512),
"event" VARCHAR(64),
"params" VARCHAR(512),
"schedule" VARCHAR(64),
"executorid" INTEGER,
"time" TIMESTAMP  DEFAULT (now())

); COMMENT ON TABLE "public"."tb_task_trigger" IS 'task触发器'; COMMENT ON COLUMN "tb_task_trigger"."id" IS '触发器id'; COMMENT ON COLUMN "tb_task_trigger"."name" IS '触发器名称'; COMMENT ON COLUMN "tb_task_trigger"."event" IS '触发器事件'; COMMENT ON COLUMN "tb_task_trigger"."executorid" IS '触发器绑定的执行executor';

INSERT INTO "public"."tb_task_trigger"("name", "description", "event", "params", "executorid") VALUES ('http-test', ' ', 'http', '{"method":"GET","url":"9","route":"/:num|isnum", "async": true}', 9);

PostgreSQL End

type TriggerController

type TriggerController struct {
	controller.ControllerWebsite
}

PostgreSQL Begin -- task触发器 CREATE SEQUENCE seq_task_trigger_id INCREMENT by 1 MINVALUE 1 START 1; CREATE TABLE tb_task_trigger(

"id" INTEGER PRIMARY KEY DEFAULT nextval('seq_task_trigger_id'),
"name" VARCHAR(64),
"description" VARCHAR(512),
"event" VARCHAR(64),
"params" VARCHAR(512),
"schedule" VARCHAR(64),
"executorid" INTEGER,
"time" TIMESTAMP  DEFAULT (now())

); COMMENT ON TABLE "public"."tb_task_trigger" IS 'task触发器'; COMMENT ON COLUMN "tb_task_trigger"."id" IS '触发器id'; COMMENT ON COLUMN "tb_task_trigger"."name" IS '触发器名称'; COMMENT ON COLUMN "tb_task_trigger"."event" IS '触发器事件'; COMMENT ON COLUMN "tb_task_trigger"."executorid" IS '触发器绑定的执行executor';

INSERT INTO "public"."tb_task_trigger"("name", "description", "event", "params", "executorid") VALUES ('http-test', ' ', 'http', '{"method":"GET","url":"9","route":"/:num|isnum", "async": true}', 9);

PostgreSQL End

func NewTriggerController

func NewTriggerController(db *sql.DB) *TriggerController

func (*TriggerController) GetCount

func (ctl *TriggerController) GetCount() interface{}

func (*TriggerController) GetIndex

func (ctl *TriggerController) GetIndex() (interface{}, error)

func (*TriggerController) GetInfoIdById

func (ctl *TriggerController) GetInfoIdById() (interface{}, error)

func (*TriggerController) GetInfoNameByName

func (ctl *TriggerController) GetInfoNameByName() (interface{}, error)

func (*TriggerController) GetList

func (ctl *TriggerController) GetList() (interface{}, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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