feat:
This commit is contained in:
parent
568ccea09a
commit
c2076338fa
13 changed files with 509 additions and 166 deletions
107
internal/tester/delivery/rabbitmq/pubsub.go
Normal file
107
internal/tester/delivery/rabbitmq/pubsub.go
Normal file
|
@ -0,0 +1,107 @@
|
|||
package rabbitmq
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.sch9.ru/new_gate/ms-tester/internal/tester"
|
||||
runnerv1 "git.sch9.ru/new_gate/ms-tester/pkg/go/gen/proto/runner/v1"
|
||||
"github.com/golang/protobuf/proto"
|
||||
amqp "github.com/rabbitmq/amqp091-go"
|
||||
)
|
||||
|
||||
func NewTesterProducer(ch *amqp.Channel, tQueueName string, rQueueName string, testerUC tester.TesterUseCase) {
|
||||
_, err := ch.QueueDeclare(
|
||||
tQueueName,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
for d := range testerUC.TestingChannel() {
|
||||
for i := 0; i < 15; i++ {
|
||||
msg := runnerv1.Instruction{
|
||||
Instruction: &runnerv1.Instruction_Run{
|
||||
Run: &runnerv1.Run{
|
||||
SolutionId: d,
|
||||
TestId: 0,
|
||||
BindingKey: rQueueName,
|
||||
},
|
||||
}}
|
||||
|
||||
body, err := proto.Marshal(&msg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = ch.Publish(
|
||||
"",
|
||||
tQueueName,
|
||||
false,
|
||||
false,
|
||||
amqp.Publishing{
|
||||
ContentType: "text/plain",
|
||||
Body: body,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
return
|
||||
}
|
||||
|
||||
func NewTesterConsumer(ch *amqp.Channel, rQueueName string, instanceName string, testerUC tester.TesterUseCase) {
|
||||
_, err := ch.QueueDeclare(
|
||||
rQueueName,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
msgs, err := ch.Consume(
|
||||
rQueueName,
|
||||
"",
|
||||
false,
|
||||
true, // each tester must have exclusive results queue
|
||||
false,
|
||||
false,
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
for d := range msgs {
|
||||
err = d.Ack(false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
msg := runnerv1.Result{}
|
||||
err = proto.Unmarshal(d.Body, &msg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(msg.String())
|
||||
|
||||
err = testerUC.ProcessResult(context.Background(), msg.GetRun().SolutionId, msg.GetRun().String())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue