Documentation
¶
Index ¶
- Constants
- Variables
- func NewEventJobStatusQueue(rdb jq.RedisClient) *jq.Queue
- func NewEventMessageQueue(rdb jq.RedisClient) *jq.Queue
- type Agent
- type AgentBasic
- type DelayedJob
- type DelayedJobInput
- type EventCenter
- type EventHandler
- type Job
- type JobBasic
- type JobInput
- type JobResult
- type Message
- type MessageInput
Constants ¶
View Source
const ( EventMessage = "message" EventJobStatus = "job:status" )
Event will publish to redis queue
View Source
const ( JobStatusQueuing = "queuing" JobStatusCanceled = "canceled" JobStatusSent = "sent" JobStatusRunning = "running" JobStatusExpired = "expired" JobStatusSucceeded = "succeeded" JobStatusFailed = "failed" )
View Source
const ( MessageTypeInfo = "info" MessageTypeWarning = "warning" MessageTypeText = "text" MessageTypeAuto = "auto" )
Variables ¶
View Source
var RESERVED = xtype.Strings{"agent", "delay", "status", "help", "delay", "group", "plan", "poster",
"link", "unlink", "follow", "unfollow", "sub", "unsub"}
Functions ¶
func NewEventJobStatusQueue ¶ added in v0.9.0
func NewEventJobStatusQueue(rdb jq.RedisClient) *jq.Queue
NewEventJobStatusQueue is stateless in local, you can new it anywhere.
func NewEventMessageQueue ¶ added in v0.9.0
func NewEventMessageQueue(rdb jq.RedisClient) *jq.Queue
NewEventMessageQueue is stateless in local, you can new it anywhere.
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 DelayedJob ¶ added in v1.2.0
type DelayedJob struct {
ID string `json:"id" gorm:"type:varchar(20);primary_key"`
JobInput
ActiveAt time.Time `json:"active_at"`
CreatedAt time.Time `json:"created_at"`
}
DelayedJob will be stored in db for future run.
type DelayedJobInput ¶ added in v1.2.0
type DelayedJobInput struct {
Message string `validate:"required,lte=255" json:"message"`
Duration string `json:"duration,omitempty"`
Minutes int `json:"minutes,omitempty"`
Hours int `json:"hours,omitempty"`
Days int `json:"days,omitempty"`
// a url, will be called after job status changed,
// left empty will notify in your default IM,
// set to "disable" will disable any notify or callback
Callback string `validate:"omitempty,lte=255" json:"callback,omitempty"`
}
DelayedJobInput just for api input
type EventCenter ¶
type EventHandler ¶
type EventHandler func(e *Message)
EventHandler handle the event, and please handle the error yourself.
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 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, if exists, will be called after sent/expired/succeeded/failed
// left empty will notify in your default IM,
// set to "disable" will disable any notify or callback
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.
type Message ¶ added in v0.9.0
type Message 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"`
}
Message will send to IM, gen by agent api, or system event.
type MessageInput ¶ added in v0.9.0
type MessageInput struct {
Message string `json:"message"`
}
Click to show internal directories.
Click to hide internal directories.