Documentation ¶
Index ¶
- Constants
- Variables
- func Ack(jobID string) (bool, error)
- func AddToBucket(b *Bucket, card *JobCard) error
- func AddToJobPool(j *Job) error
- func AddToReadyQueue(jobID string) error
- func Encode(j *Job) (string, error)
- func FormatTime(t time.Time) string
- func GetBucketJobNum(b *Bucket) int
- func GetBucketKeyByID(id string) string
- func GetJobConsumeNum(jobID string) (int, error)
- func GetJobDetailByID(jobID string) (map[string]string, error)
- func GetJobKeyByID(id string) string
- func GetJobQueueByTopic(topic string) string
- func GetJobStatus(jobID string) (int, error)
- func GetTopicByJobID(jobID string) (string, error)
- func IncrJobConsumeNum(jobID string) (bool, error)
- func Pop(topics ...string) (map[string]string, error)
- func Push(j string) error
- func RemoveFromBucket() error
- func RetrivalTimeoutJobs(b *Bucket) (jobIDs []string, nextTime int, err error)
- func SecToTimeString(t interface{}) string
- func SetJobStatus(jobID string, status int) error
- func UnixToFormatTime(t interface{}) string
- type Bucket
- type ByID
- type ByNum
- type Dispatcher
- type IServer
- type Job
- type JobCard
- type MQ
- type RPCServer
- type RedisDB
- func (db *RedisDB) Bool(command string, args ...interface{}) (bool, error)
- func (db *RedisDB) Do(command string, args ...interface{}) (interface{}, error)
- func (db *RedisDB) InitPool(host, port, password string, maxIDle, maxActive int)
- func (db *RedisDB) Int(command string, args ...interface{}) (int, error)
- func (db *RedisDB) Ints(command string, args ...interface{}) ([]int, error)
- func (db *RedisDB) String(command string, args ...interface{}) (string, error)
- func (db *RedisDB) StringMap(command string, args ...interface{}) (map[string]string, error)
- func (db *RedisDB) Strings(command string, args ...interface{}) ([]string, error)
- type Service
Constants ¶
View Source
const ( // JobStatusDefault 默认状态 JobStatusDefault = iota // JobStatusDelay delay:不可执行状态,等待时钟周期 JobStatusDelay // JobStatusReady ready:可执行状态,等待消费 JobStatusReady // JobStatusReserved reserved: 已被消费者读取,但还未得到消费者的响应(delete、finish) JobStatusReserved )
View Source
const ( // JobPoolKey jobpool JobPoolKey = "mq:jobpool" // BucketKey bucket BucketKey = "mq:bucket" // ReadyQueueKey readyqueue ReadyQueueKey = "mq:readyqueue" // ReadyQueueCacheKey rqcachekey ReadyQueueCacheKey = "mq:readyqueuecachekey" )
Variables ¶
View Source
var ( // ErrJobIDEmpty job.id is empty ErrJobIDEmpty = errors.New("job.id is empty") // ErrJobTopicEmpty job.topic is empty ErrJobTopicEmpty = errors.New("job.topic is empty") )
Functions ¶
func AddToBucket ¶
AddToBucket 添加到bucket 有序集合score = 延迟秒数 + 当前时间戳, member = jobID 并且设置job.status = JobStatusDelay TTR>0时,有可能job先被删除后再添加到bucket,所以添加到bucket前需要检测job是否存在
func GetJobDetailByID ¶
GetJobDetailByID 获取消息的detail
func GetJobQueueByTopic ¶
GetJobQueueByTopic GetJobQueueByTopic
func GetTopicByJobID ¶
GetTopicByJobID 获取消息的topic
func IncrJobConsumeNum ¶
IncrJobConsumeNum 消息被消费的次数+1
func RetrivalTimeoutJobs ¶
RetrivalTimeoutJobs 从指定bucket检索到期的job nextTime参数如下:
-1 当前bucket已经没有jobs >0 当前bucket下个job到期时间
可能整个事务需要保证原子一致性
func SecToTimeString ¶
func SecToTimeString(t interface{}) string
SecToTimeString 172992 to "48h3m12s"
func UnixToFormatTime ¶
func UnixToFormatTime(t interface{}) string
UnixToFormatTime unix to "2019-06-07 12:00:00"
Types ¶
type Bucket ¶
type Bucket struct { sync.Mutex ID string JobNum int NextTime time.Time // contains filtered or unexported fields }
Bucket Bucket
type Dispatcher ¶
type Dispatcher struct { TTRBuckets []*Bucket // contains filtered or unexported fields }
Dispatcher 调度器 添加Job到Job Pool 调度Job分配到bucket 管理bucket
func (*Dispatcher) AddToJobPool ¶
func (d *Dispatcher) AddToJobPool(j *Job) error
AddToJobPool 添加任务到对象池
type Job ¶
type Job struct { ID string `redis:"id"` Topic string `redis:"topic"` Delay int `redis:"delay"` TTR int `redis:"TTR"` // time-to-run Body string `redis:"body"` Status int `redis:"status"` ConsumeNum int `redis:"consume_num"` }
Job 进入队列的消息结构
type RedisDB ¶
RedisDB redis连接池
var Redis *RedisDB
Redis 存放redis连接池的变量
Click to show internal directories.
Click to hide internal directories.