代码拉取完成,页面将自动刷新
package msgqueue
import (
"errors"
"fmt"
"time"
"github.com/vmihailenco/msgpack"
)
var ErrDuplicate = errors.New("queue: message with such name already exists")
// Message is used to create and retrieve messages from a queue.
type Message struct {
// SQS/IronMQ message id.
Id string
// Optional name for the message. Messages with the same name
// are processed only once.
Name string
// Delay specifies the duration the queue must wait
// before executing the message.
Delay time.Duration
// Function args passed to the handler.
Args []interface{}
// Text representation of the Args.
Body string
// SQS/IronMQ reservation id that is used to release/delete the message..
ReservationId string
// The number of times the message has been reserved or released.
ReservedCount int
Err error
}
func NewMessage(args ...interface{}) *Message {
return &Message{
Args: args,
}
}
func (m *Message) String() string {
return fmt.Sprintf(
"Message<Id=%q Name=%q ReservedCount=%d>",
m.Id, m.Name, m.ReservedCount,
)
}
// SetDelayName sets delay and generates message name from the args.
func (m *Message) SetDelayName(delay time.Duration, args ...interface{}) {
m.Name = argsName(append(args, timeSlot(delay)))
m.Delay = delay
}
func timeSlot(resolution time.Duration) int64 {
if resolution <= 0 {
return 0
}
return time.Now().UnixNano() / int64(resolution)
}
func argsName(args []interface{}) string {
b, _ := msgpack.Marshal(args...)
return string(b)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。