types

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventTypeInfo    = "info"
	EventTypeWarning = "warning"
	EventTypeText    = "text"
)
View Source
const (
	JobStatusQueuing   = "queuing"
	JobStatusCanceled  = "canceled"
	JobStatusSent      = "sent"
	JobStatusRunning   = "running"
	JobStatusExpired   = "expired"
	JobStatusSucceeded = "succeeded"
	JobStatusFailed    = "failed"
)

Variables

View Source
var RESERVED = xtype.Strings{"agent", "status", "help", "delay", "group"}

Functions

This section is empty.

Types

type Agent

type Agent struct {
	ID     string `json:"id" gorm:"type:varchar(20);primary_key"`
	Secret string `json:"-" gorm:"type:varchar(20);index"`
	UserID string `json:"user_id" gorm:"type:varchar(20);index:idx_uid;uniqueIndex:idx_un1;uniqueIndex:idx_un2"`
	Name   string `json:"name" gorm:"type:varchar(50);uniqueIndex:idx_un1"`
	Alias  string `json:"alias" gorm:"type:varchar(50);uniqueIndex:idx_un2"`
	Remark string `json:"remark"`
	// IP address last connected from
	IP string `json:"ip" gorm:"type:varchar(50)"`
	// Only update after a agent offline, means last activated at that time.
	ActivatedAt *time.Time `json:"activated_at"`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
}

Agent belongs to user, have id and secret, saved in db.

type AgentBasic

type AgentBasic struct {
	Name   string `json:"name"`
	Alias  string `json:"alias"`
	Remark string `json:"remark"`
}

AgentBasic used for agent creation ui

type Event

type Event struct {
	ID        string    `json:"id"`
	AgentID   string    `json:"agent_id"`
	UserID    string    `json:"user_id"`
	Type      string    `json:"type"`
	Message   string    `json:"message"`
	CreatedAt time.Time `json:"created_at"`
}

type EventCenter

type EventCenter interface {
	// Pub publish a event to a queue or pool
	Pub(e *Event) error
	// Get a event, nil if no event found
	Get() (*Event, error)
	// StartWorker to check and get new event periodically in background
	StartWorker(ctx context.Context, handler EventHandler)
}

type EventHandler

type EventHandler func(e *Event)

EventHandler handle the event, and please handle the error yourself.

type EventInput

type EventInput struct {
	Message string `json:"message"`
}

type Job

type Job struct {
	ID string `json:"id" gorm:"type:varchar(20);primary_key"`
	JobInput
	// queuing/canceled/sent/expired/succeeded/failed
	Status string `json:"status" gorm:"type:varchar(10)"`
	// agent returned, job log or other message
	Result      string     `json:"result" gorm:"type:varchar(1024)"`
	CreatedAt   time.Time  `json:"created_at" gorm:"index:by_user;index:by_agent"`
	SentAt      *time.Time `json:"sent_at,omitempty"`
	CanceledAt  *time.Time `json:"canceled_at,omitempty"`
	ExpiredAt   *time.Time `json:"expired_at,omitempty"`
	SucceededAt *time.Time `json:"succeeded_at,omitempty"`
	FailedAt    *time.Time `json:"failed_at,omitempty"`
}

Job will be saved in db, it's a gorm mysql model

type JobBasic

type JobBasic struct {
	ID      string `json:"id"`
	Message string `json:"message"`
}

JobBasic will be pulled by agent

type JobInput

type JobInput struct {
	UserID  string `json:"user_id" gorm:"type:varchar(20);index:by_user"`
	AgentID string `json:"agent_id" gorm:"type:varchar(20);index:by_agent"`
	// job payload
	Message string `json:"message" gorm:"type:varchar(255)" validate:"required,lte=255"`
	// source context, any string defined by source
	Source string `json:"source" gorm:"type:varchar(255)" validate:"omitempty,lte=255"`
	// callback url, will be called after expired/succeeded/failed
	Callback string `json:"callback" gorm:"type:varchar(255)" validate:"omitempty,lte=255"`
}

JobInput is input fields which upstream service passed

type JobResult

type JobResult struct {
	// agent returned, job log or other message
	Result string `json:"result,omitempty"`
}

JobResult is reported by agent The length of result is not limited, if it longer than 1024, will be cut.

Jump to

Keyboard shortcuts

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