-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallback.go
78 lines (64 loc) · 1.94 KB
/
callback.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package judger
import (
"fmt"
"github.com/Rabbit-OJ/Rabbit-OJ-Judger/config"
"github.com/Rabbit-OJ/Rabbit-OJ-Judger/logger"
JudgerModels "github.com/Rabbit-OJ/Rabbit-OJ-Judger/models"
"github.com/Rabbit-OJ/Rabbit-OJ-Judger/mq"
"github.com/Rabbit-OJ/Rabbit-OJ-Judger/protobuf"
"github.com/golang/protobuf/proto"
"sync"
)
type JudgeResponseCallback = func(sid uint32, isContest bool, judgeResult []*JudgerModels.JudgeResult)
var (
CallbackWaitGroup sync.WaitGroup
OnJudgeResponse []JudgeResponseCallback
)
func CallbackAllError(status string, sid uint32, isContest bool, datasetCount int) {
go func() {
CallbackWaitGroup.Add(1)
defer CallbackWaitGroup.Done()
logger.Printf("(%d) Callback judge error with status: %s \n", sid, status)
ceResult := make([]*protobuf.JudgeCaseResult, datasetCount)
for i := range ceResult {
ceResult[i] = &protobuf.JudgeCaseResult{
Status: status,
}
}
response := &protobuf.JudgeResponse{
Sid: sid,
Result: ceResult,
IsContest: isContest,
}
pro, err := proto.Marshal(response)
if err != nil {
logger.Println(err)
return
}
if err := mq.PublishMessageSync(config.JudgeResponseTopicName, []byte(fmt.Sprintf("%d", sid)), pro);
err != nil {
logger.Printf("[Callback] Error when callback error message to queue %+v \n", err)
}
}()
}
func CallbackSuccess(sid uint32, isContest bool, resultList []*protobuf.JudgeCaseResult) {
go func() {
CallbackWaitGroup.Add(1)
defer CallbackWaitGroup.Done()
logger.Printf("(%d) Callback judge success \n", sid)
response := &protobuf.JudgeResponse{
Sid: sid,
Result: resultList,
IsContest: isContest,
}
pro, err := proto.Marshal(response)
if err != nil {
logger.Println(err)
return
}
if err := mq.PublishMessageSync(config.JudgeResponseTopicName, []byte(fmt.Sprintf("%d", sid)), pro);
err != nil {
logger.Printf("[Callback] Error when callback success message to queue %+v \n", err)
}
}()
}