forked from yuxh/gearman-go
Modified the api, added the interrupt for the example.
This commit is contained in:
parent
79e383a639
commit
b8ec3fd242
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
client := client.NewClient()
|
||||
client := client.New()
|
||||
defer client.Close()
|
||||
if err := client.AddServer("127.0.0.1:4730"); err != nil {
|
||||
log.Fatalln(err)
|
||||
|
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"bitbucket.org/mikespook/gearman-go/gearman"
|
||||
"bitbucket.org/mikespook/gearman-go/gearman/worker"
|
||||
"bitbucket.org/mikespook/golib/util"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
@ -14,12 +15,18 @@ func ToUpper(job *worker.WorkerJob) ([]byte, error) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
w := worker.NewWorker()
|
||||
defer w.Close()
|
||||
w := worker.New()
|
||||
w.AddServer("127.0.0.1:4730")
|
||||
w.AddFunction("ToUpper", ToUpper, 0)
|
||||
w.AddFunction("ToUpperTimeOut5", ToUpper, 5)
|
||||
|
||||
// Catch the interrupt to exit the working loop.
|
||||
sh := util.NewSignalHandler(func() bool {
|
||||
w.Close()
|
||||
return true
|
||||
}, func() bool {return true})
|
||||
go sh.Loop()
|
||||
|
||||
go func() {
|
||||
log.Println("start worker")
|
||||
for {
|
||||
|
@ -31,7 +31,7 @@ type Client struct {
|
||||
}
|
||||
|
||||
// Create a new client.
|
||||
func NewClient() (client *Client) {
|
||||
func New() (client *Client) {
|
||||
client = &Client{JobQueue: make(chan *ClientJob, gearman.QUEUE_CAP),
|
||||
incoming: make(chan []byte, gearman.QUEUE_CAP),
|
||||
UId: 1}
|
||||
|
@ -46,7 +46,7 @@ type Worker struct {
|
||||
}
|
||||
|
||||
// Get a new worker
|
||||
func NewWorker() (worker *Worker) {
|
||||
func New() (worker *Worker) {
|
||||
worker = &Worker{
|
||||
// job server list
|
||||
clients: make([]*jobAgent, 0, gearman.WORKER_SERVER_CAP),
|
||||
|
Loading…
Reference in New Issue
Block a user