在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:jrallison/go-workers开源软件地址:https://github.com/jrallison/go-workers开源编程语言:Go 100.0%开源软件介绍:Sidekiq compatible background workers in golang.
Example usage: package main
import (
"github.com/jrallison/go-workers"
)
func myJob(message *workers.Msg) {
// do something with your message
// message.Jid()
// message.Args() is a wrapper around go-simplejson (http://godoc.org/github.com/bitly/go-simplejson)
}
type myMiddleware struct{}
func (r *myMiddleware) Call(queue string, message *workers.Msg, next func() bool) (acknowledge bool) {
// do something before each message is processed
acknowledge = next()
// do something after each message is processed
return
}
func main() {
workers.Configure(map[string]string{
// location of redis instance
"server": "localhost:6379",
// instance of the database
"database": "0",
// number of connections to keep open with redis
"pool": "30",
// unique process id for this instance of workers (for proper recovery of inprogress jobs on crash)
"process": "1",
})
workers.Middleware.Append(&myMiddleware{})
// pull messages from "myqueue" with concurrency of 10
workers.Process("myqueue", myJob, 10)
// pull messages from "myqueue2" with concurrency of 20
workers.Process("myqueue2", myJob, 20)
// Add a job to a queue
workers.Enqueue("myqueue3", "Add", []int{1, 2})
// Add a job to a queue with retry
workers.EnqueueWithOptions("myqueue3", "Add", []int{1, 2}, workers.EnqueueOptions{Retry: true})
// stats will be available at http://localhost:8080/stats
go workers.StatsServer(8080)
// Blocks until process is told to exit via unix signal
workers.Run()
} Initial development sponsored by Customer.io |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论