Documentation
¶
Index ¶
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 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
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.