-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.go
62 lines (57 loc) · 1.41 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package spread_compute
import (
"fmt"
"log"
)
type Call int
type CommonFunctionCallArgs struct {
Datas []interface{}
GroupId int64
CallType string
}
type Status bool
func (c *Call) CallFunction(arg *CommonFunctionCallArgs, status *Status) error {
switch arg.CallType {
case "producer":
rfLock.Lock()
f, exists := RegistedProducerFunctions[arg.GroupId]
rfLock.Unlock()
if !exists {
*status = false
return fmt.Errorf("groupId:%d Producer function does not exists! \n", arg.GroupId)
}
if datas, err := f.ProduceData(); err != nil {
*status = false
log.Printf("Call groupId %d function failed! \n", arg.GroupId)
return err
} else {
log.Printf("Start to shuffle producer data!data's length is %d \n", len(datas))
err := ShuffleData(arg.GroupId, datas)
if err != nil {
*status = false
log.Printf("Call ShuffleData failed !err:%s \n", err)
return err
}
}
case "consumer":
rfLock.Lock()
_, exists := RegistedConsumerFunctions[arg.GroupId]
rfLock.Unlock()
if exists {
err := ConsumeData(arg.GroupId, arg.Datas)
if err != nil {
*status = false
return fmt.Errorf("consume data failed ! err:%s \n", err)
}
} else {
*status = false
log.Printf("Function does not exist! \n")
return fmt.Errorf("Function does not exist! \n")
}
default:
*status = false
return fmt.Errorf("illegal args common function call args!")
}
*status = true
return nil
}