forked from yuxh/gearman-go
go fmt
This commit is contained in:
parent
2b4cc002d1
commit
2ee2be0891
@ -11,17 +11,17 @@ import (
|
||||
|
||||
// The agent of job server.
|
||||
type agent struct {
|
||||
conn net.Conn
|
||||
worker *Worker
|
||||
in chan []byte
|
||||
net, addr string
|
||||
isConn bool
|
||||
conn net.Conn
|
||||
worker *Worker
|
||||
in chan []byte
|
||||
net, addr string
|
||||
isConn bool
|
||||
}
|
||||
|
||||
// Create the agent of job server.
|
||||
func newAgent(net, addr string, worker *Worker) (a *agent, err error) {
|
||||
a = &agent{
|
||||
net: net,
|
||||
net: net,
|
||||
addr: addr,
|
||||
worker: worker,
|
||||
in: make(chan []byte, QUEUE_SIZE),
|
||||
|
@ -7,17 +7,17 @@ package worker
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Worker side job
|
||||
type inPack struct {
|
||||
dataType uint32
|
||||
dataType uint32
|
||||
data []byte
|
||||
handle, uniqueId, fn string
|
||||
a *agent
|
||||
a *agent
|
||||
}
|
||||
|
||||
// Create a new job
|
||||
@ -38,7 +38,7 @@ func (inpack *inPack) SendData(data []byte) {
|
||||
l := hl + len(data) + 1
|
||||
outpack.data = getBuffer(l)
|
||||
copy(outpack.data, []byte(inpack.handle))
|
||||
copy(outpack.data[hl + 1:], data)
|
||||
copy(outpack.data[hl+1:], data)
|
||||
inpack.a.write(outpack)
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ func (inpack *inPack) SendWarning(data []byte) {
|
||||
l := hl + len(data) + 1
|
||||
outpack.data = getBuffer(l)
|
||||
copy(outpack.data, []byte(inpack.handle))
|
||||
copy(outpack.data[hl + 1:], data)
|
||||
copy(outpack.data[hl+1:], data)
|
||||
inpack.a.write(outpack)
|
||||
}
|
||||
|
||||
@ -70,7 +70,6 @@ func (inpack *inPack) UpdateStatus(numerator, denominator int) {
|
||||
inpack.a.write(outpack)
|
||||
}
|
||||
|
||||
|
||||
// Decode job from byte slice
|
||||
func decodeInPack(data []byte) (inpack *inPack, l int, err error) {
|
||||
if len(data) < MIN_PACKET_LEN { // valid package should not less 12 bytes
|
||||
|
@ -5,10 +5,10 @@
|
||||
package worker
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"sync"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -46,8 +46,8 @@ type Worker struct {
|
||||
Id string
|
||||
// assign a ErrFunc to handle errors
|
||||
ErrorHandler ErrorHandler
|
||||
JobHandler JobHandler
|
||||
mutex sync.Mutex
|
||||
JobHandler JobHandler
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// Get a new worker
|
||||
@ -78,7 +78,7 @@ func (worker *Worker) AddServer(net, addr string) (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
worker.agents[net + addr] = a
|
||||
worker.agents[net+addr] = a
|
||||
return
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ func (worker *Worker) addFunc(funcname string, timeout uint32) {
|
||||
outpack.data = getBuffer(l + 5)
|
||||
copy(outpack.data, []byte(funcname))
|
||||
outpack.data[l] = '\x00'
|
||||
binary.BigEndian.PutUint32(outpack.data[l + 1:], timeout)
|
||||
binary.BigEndian.PutUint32(outpack.data[l+1:], timeout)
|
||||
}
|
||||
worker.broadcast(outpack)
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package worker
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"testing"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var worker *Worker
|
||||
|
Loading…
Reference in New Issue
Block a user