Skip to content

Commit

Permalink
fix bags
Browse files Browse the repository at this point in the history
  • Loading branch information
Prrromanssss committed Feb 16, 2024
1 parent b92f1d5 commit a97d78e
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 64 deletions.
Binary file modified backend/cmd/daee/main
Binary file not shown.
2 changes: 1 addition & 1 deletion backend/config/rabbitmq_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func NewAMQPConsumer(amqpCfg *AMQPConfig, queueName string) (*AMQPConsumer, erro
msgs, err := amqpCfg.ChannelForConsume.Consume(
queue.Name,
"",
true,
false,
false,
false,
false,
Expand Down
53 changes: 22 additions & 31 deletions backend/daee.log
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
2024/02/16 01:57:08 Successfully connected to DB instance
2024/02/16 01:57:08 Successfully connected to RabbitMQ instance
2024/02/16 01:57:08 Successfully connected to RabbitMQ instance
2024/02/16 01:57:08 Server starting on port 3000
2024/02/16 01:57:15 Send message from orchestrator to agent agregator
2024/02/16 01:57:15 Agent agregator consume message from orchestrator
2024/02/16 01:57:15 [1 2 + 3 4 + +]
2024/02/16 01:57:15 Publishing message to Queue: Queue for sending expressions to agents
2024/02/16 01:57:15 Publishing message to Queue: Queue for sending expressions to agents
2024/02/16 01:57:15 Agent consume msg from agent agregator [123 34 101 120 112 114 101 115 115 105 111 110 95 105 100 34 58 34 52 97 48 51 102 55 98 51 45 50 54 49 53 45 52 101 48 48 45 57 51 102 48 45 97 102 50 101 52 57 99 100 55 102 99 102 34 44 34 116 111 107 101 110 34 58 34 51 32 52 32 43 34 44 34 101 120 112 114 101 115 115 105 111 110 34 58 34 49 32 50 32 43 32 51 32 52 32 43 32 43 34 44 34 114 101 115 117 108 116 34 58 48 44 34 105 115 95 99 111 109 112 117 116 105 110 103 34 58 102 97 108 115 101 44 34 105 115 95 112 105 110 103 34 58 102 97 108 115 101 44 34 97 103 101 110 116 95 105 100 34 58 34 48 48 48 48 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 48 48 48 48 48 48 48 48 34 125]
2024/02/16 01:57:15 Agent consume msg from agent agregator [123 34 101 120 112 114 101 115 115 105 111 110 95 105 100 34 58 34 52 97 48 51 102 55 98 51 45 50 54 49 53 45 52 101 48 48 45 57 51 102 48 45 97 102 50 101 52 57 99 100 55 102 99 102 34 44 34 116 111 107 101 110 34 58 34 49 32 50 32 43 34 44 34 101 120 112 114 101 115 115 105 111 110 34 58 34 49 32 50 32 43 32 51 32 52 32 43 32 43 34 44 34 114 101 115 117 108 116 34 58 48 44 34 105 115 95 99 111 109 112 117 116 105 110 103 34 58 102 97 108 115 101 44 34 105 115 95 112 105 110 103 34 58 102 97 108 115 101 44 34 97 103 101 110 116 95 105 100 34 58 34 48 48 48 48 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 48 48 48 48 48 48 48 48 34 125]
2024/02/16 01:57:25 Agent consume message from computers &{4a03f7b3-2615-4e00-93f0-af2e49cd7fcf 3 4 + 1 2 + 3 4 + + 7 false false 00000000-0000-0000-0000-000000000000}
2024/02/16 01:57:25 Successfully connected to RabbitMQ instance
2024/02/16 01:57:25 Publishing message to Queue: Queue for consuming results and pings from agents
2024/02/16 01:57:25 Agent agregator consume message from agent [123 34 101 120 112 114 101 115 115 105 111 110 95 105 100 34 58 34 52 97 48 51 102 55 98 51 45 50 54 49 53 45 52 101 48 48 45 57 51 102 48 45 97 102 50 101 52 57 99 100 55 102 99 102 34 44 34 116 111 107 101 110 34 58 34 51 32 52 32 43 34 44 34 101 120 112 114 101 115 115 105 111 110 34 58 34 49 32 50 32 43 32 51 32 52 32 43 32 43 34 44 34 114 101 115 117 108 116 34 58 55 44 34 105 115 95 99 111 109 112 117 116 105 110 103 34 58 102 97 108 115 101 44 34 105 115 95 112 105 110 103 34 58 102 97 108 115 101 44 34 97 103 101 110 116 95 105 100 34 58 34 48 48 48 48 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 48 48 48 48 48 48 48 48 34 125]
2024/02/16 01:57:25 Agent consume message from computers &{4a03f7b3-2615-4e00-93f0-af2e49cd7fcf 1 2 + 1 2 + 3 4 + + 3 false false 00000000-0000-0000-0000-000000000000}
2024/02/16 01:57:25 Successfully connected to RabbitMQ instance
2024/02/16 01:57:25 Publishing message to Queue: Queue for consuming results and pings from agents
2024/02/16 02:03:53 Successfully connected to DB instance
2024/02/16 02:03:53 Successfully connected to RabbitMQ instance
2024/02/16 02:03:53 Agent agregator consume message from agent [123 34 101 120 112 114 101 115 115 105 111 110 95 105 100 34 58 34 52 97 48 51 102 55 98 51 45 50 54 49 53 45 52 101 48 48 45 57 51 102 48 45 97 102 50 101 52 57 99 100 55 102 99 102 34 44 34 116 111 107 101 110 34 58 34 49 32 50 32 43 34 44 34 101 120 112 114 101 115 115 105 111 110 34 58 34 49 32 50 32 43 32 51 32 52 32 43 32 43 34 44 34 114 101 115 117 108 116 34 58 51 44 34 105 115 95 99 111 109 112 117 116 105 110 103 34 58 102 97 108 115 101 44 34 105 115 95 112 105 110 103 34 58 102 97 108 115 101 44 34 97 103 101 110 116 95 105 100 34 58 34 48 48 48 48 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 48 48 48 48 48 48 48 48 34 125]
2024/02/16 02:03:53 Successfully connected to RabbitMQ instance
2024/02/16 02:03:53 Server starting on port 3000
2024/02/16 02:04:05 Send message from orchestrator to agent agregator
2024/02/16 02:04:05 Agent agregator consume message from orchestrator
2024/02/16 02:04:05 [1 2 + 3 +]
2024/02/16 02:04:05 Publishing message to Queue: Queue for sending expressions to agents
2024/02/16 02:04:05 Agent consume msg from agent agregator [123 34 101 120 112 114 101 115 115 105 111 110 95 105 100 34 58 34 101 101 48 53 51 53 98 52 45 101 100 57 97 45 52 102 54 100 45 57 100 52 55 45 55 101 99 54 55 49 48 57 100 52 53 53 34 44 34 116 111 107 101 110 34 58 34 49 32 50 32 43 34 44 34 101 120 112 114 101 115 115 105 111 110 34 58 34 49 32 50 32 43 32 51 32 43 34 44 34 114 101 115 117 108 116 34 58 48 44 34 105 115 95 99 111 109 112 117 116 105 110 103 34 58 102 97 108 115 101 44 34 105 115 95 112 105 110 103 34 58 102 97 108 115 101 44 34 97 103 101 110 116 95 105 100 34 58 34 48 48 48 48 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 48 48 48 48 48 48 48 48 34 125]
2024/02/16 02:04:23 Agent consume message from computers &{ee0535b4-ed9a-4f6d-9d47-7ec67109d455 1 2 + 1 2 + 3 + 3 false false 00000000-0000-0000-0000-000000000000}
2024/02/16 02:04:23 Successfully connected to RabbitMQ instance
2024/02/16 02:04:23 Publishing message to Queue: Queue for consuming results and pings from agents
2024/02/16 12:48:20 Successfully connected to DB instance
2024/02/16 12:48:20 Successfully connected to RabbitMQ instance
2024/02/16 12:48:20 Successfully connected to RabbitMQ instance
2024/02/16 12:48:20 Server starting on port 3000
2024/02/16 12:48:34 Send message from orchestrator to agent agregator
2024/02/16 12:48:34 Agent agregator consume message from orchestrator
2024/02/16 12:48:34 [1 2 + 3 4 + +]
2024/02/16 12:48:34 Publishing message to Queue: Queue for sending expressions to agents
2024/02/16 12:48:34 Publishing message to Queue: Queue for sending expressions to agents
2024/02/16 12:48:34 Agent consume msg from agent agregator [123 34 101 120 112 114 101 115 115 105 111 110 95 105 100 34 58 34 98 54 100 56 55 97 100 48 45 57 52 57 51 45 52 56 102 53 45 57 55 98 57 45 54 57 97 56 54 54 56 52 50 55 102 102 34 44 34 116 111 107 101 110 34 58 34 51 32 52 32 43 34 44 34 101 120 112 114 101 115 115 105 111 110 34 58 34 49 32 50 32 43 32 51 32 52 32 43 32 43 34 44 34 114 101 115 117 108 116 34 58 48 44 34 105 115 95 99 111 109 112 117 116 105 110 103 34 58 102 97 108 115 101 44 34 105 115 95 112 105 110 103 34 58 102 97 108 115 101 44 34 97 103 101 110 116 95 105 100 34 58 34 48 48 48 48 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 48 48 48 48 48 48 48 48 34 125]
2024/02/16 12:48:34 Agent consume msg from agent agregator [123 34 101 120 112 114 101 115 115 105 111 110 95 105 100 34 58 34 98 54 100 56 55 97 100 48 45 57 52 57 51 45 52 56 102 53 45 57 55 98 57 45 54 57 97 56 54 54 56 52 50 55 102 102 34 44 34 116 111 107 101 110 34 58 34 49 32 50 32 43 34 44 34 101 120 112 114 101 115 115 105 111 110 34 58 34 49 32 50 32 43 32 51 32 52 32 43 32 43 34 44 34 114 101 115 117 108 116 34 58 48 44 34 105 115 95 99 111 109 112 117 116 105 110 103 34 58 102 97 108 115 101 44 34 105 115 95 112 105 110 103 34 58 102 97 108 115 101 44 34 97 103 101 110 116 95 105 100 34 58 34 48 48 48 48 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 48 48 48 48 48 48 48 48 34 125]
2024/02/16 12:48:44 Agent consume message from computers &{b6d87ad0-9493-48f5-97b9-69a8668427ff 3 4 + 1 2 + 3 4 + + 7 false false 00000000-0000-0000-0000-000000000000}
2024/02/16 12:48:44 Publishing message to Queue: Queue for consuming results and pings from agents
2024/02/16 12:48:44 Agent agregator consume message from agent [123 34 101 120 112 114 101 115 115 105 111 110 95 105 100 34 58 34 98 54 100 56 55 97 100 48 45 57 52 57 51 45 52 56 102 53 45 57 55 98 57 45 54 57 97 56 54 54 56 52 50 55 102 102 34 44 34 116 111 107 101 110 34 58 34 51 32 52 32 43 34 44 34 101 120 112 114 101 115 115 105 111 110 34 58 34 49 32 50 32 43 32 51 32 52 32 43 32 43 34 44 34 114 101 115 117 108 116 34 58 55 44 34 105 115 95 99 111 109 112 117 116 105 110 103 34 58 102 97 108 115 101 44 34 105 115 95 112 105 110 103 34 58 102 97 108 115 101 44 34 97 103 101 110 116 95 105 100 34 58 34 48 48 48 48 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 48 48 48 48 48 48 48 48 34 125]
2024/02/16 12:48:44 Agent consume message from computers &{b6d87ad0-9493-48f5-97b9-69a8668427ff 1 2 + 1 2 + 3 4 + + 3 false false 00000000-0000-0000-0000-000000000000}
2024/02/16 12:48:44 Publishing message to Queue: Queue for consuming results and pings from agents
2024/02/16 12:48:44 Agent agregator consume message from agent [123 34 101 120 112 114 101 115 115 105 111 110 95 105 100 34 58 34 98 54 100 56 55 97 100 48 45 57 52 57 51 45 52 56 102 53 45 57 55 98 57 45 54 57 97 56 54 54 56 52 50 55 102 102 34 44 34 116 111 107 101 110 34 58 34 49 32 50 32 43 34 44 34 101 120 112 114 101 115 115 105 111 110 34 58 34 49 32 50 32 43 32 51 32 52 32 43 32 43 34 44 34 114 101 115 117 108 116 34 58 51 44 34 105 115 95 99 111 109 112 117 116 105 110 103 34 58 102 97 108 115 101 44 34 105 115 95 112 105 110 103 34 58 102 97 108 115 101 44 34 97 103 101 110 116 95 105 100 34 58 34 48 48 48 48 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 48 48 48 48 48 48 48 48 34 125]
2024/02/16 12:48:44 Publishing message to Queue: Queue for sending expressions to agents
2024/02/16 12:48:44 Agent consume msg from agent agregator [123 34 101 120 112 114 101 115 115 105 111 110 95 105 100 34 58 34 98 54 100 56 55 97 100 48 45 57 52 57 51 45 52 56 102 53 45 57 55 98 57 45 54 57 97 56 54 54 56 52 50 55 102 102 34 44 34 116 111 107 101 110 34 58 34 51 32 55 32 43 34 44 34 101 120 112 114 101 115 115 105 111 110 34 58 34 51 32 55 32 43 34 44 34 114 101 115 117 108 116 34 58 48 44 34 105 115 95 99 111 109 112 117 116 105 110 103 34 58 102 97 108 115 101 44 34 105 115 95 112 105 110 103 34 58 102 97 108 115 101 44 34 97 103 101 110 116 95 105 100 34 58 34 48 48 48 48 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 48 48 48 48 48 48 48 48 34 125]
2024/02/16 12:48:54 Agent consume message from computers &{b6d87ad0-9493-48f5-97b9-69a8668427ff 3 7 + 3 7 + 10 false false 00000000-0000-0000-0000-000000000000}
2024/02/16 12:48:54 Publishing message to Queue: Queue for consuming results and pings from agents
2024/02/16 12:48:54 Agent agregator consume message from agent [123 34 101 120 112 114 101 115 115 105 111 110 95 105 100 34 58 34 98 54 100 56 55 97 100 48 45 57 52 57 51 45 52 56 102 53 45 57 55 98 57 45 54 57 97 56 54 54 56 52 50 55 102 102 34 44 34 116 111 107 101 110 34 58 34 51 32 55 32 43 34 44 34 101 120 112 114 101 115 115 105 111 110 34 58 34 51 32 55 32 43 34 44 34 114 101 115 117 108 116 34 58 49 48 44 34 105 115 95 99 111 109 112 117 116 105 110 103 34 58 102 97 108 115 101 44 34 105 115 95 112 105 110 103 34 58 102 97 108 115 101 44 34 97 103 101 110 116 95 105 100 34 58 34 48 48 48 48 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 45 48 48 48 48 48 48 48 48 48 48 48 48 34 125]
36 changes: 20 additions & 16 deletions backend/internal/database/expressions.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions backend/pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ func AgentService(agent *Agent) {
return
}
}

}(msgFromAgentAgregator)

}
}()

Expand Down
37 changes: 26 additions & 11 deletions backend/pkg/agent/agent_agregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"log"
"strconv"
"sync"
"time"

"github.com/google/uuid"
Expand All @@ -23,6 +24,7 @@ type AgentAgregator struct {
tasks chan MessageFromOrchestrator
amqpProducer *config.AMQPProducer
amqpConsumer *config.AMQPConsumer
mu *sync.Mutex
}

type MessageFromOrchestrator struct {
Expand Down Expand Up @@ -68,6 +70,7 @@ func NewAgentAgregator(
tasks: make(chan MessageFromOrchestrator),
amqpProducer: amqpProd,
amqpConsumer: amqpCons,
mu: &sync.Mutex{},
}
}

Expand Down Expand Up @@ -155,14 +158,35 @@ func AgregateAgents(agentAg *AgentAgregator) {
log.Fatalf("Can't update last ping: %v", err)
}
} else {
agentAg.mu.Lock()
expression, err := agentAg.dbConfig.DB.GetExpressionByID(context.Background(), exprMsg.ExpressionID)
if err != nil {
agentAg.mu.Unlock()
log.Printf("Can't get expression by id: %v", err)
return
}

newExpr, newToken, err := orchestrator.InsertResultToToken(
exprMsg.Expression,
expression.ParseData,
exprMsg.Token,
exprMsg.Result,
)
if err != nil {
log.Fatalf("Can't get expression by id: %v", err)
log.Fatalf("Can't insert tokens to expression: %v", err)
}

err = agentAg.dbConfig.DB.UpdateExpressionParseData(
context.Background(),
database.UpdateExpressionParseDataParams{
ID: exprMsg.ExpressionID,
ParseData: newExpr,
})

if err != nil {
log.Fatalf("Can't update expression data: %v", err)
}
agentAg.mu.Unlock()

result, err := strconv.Atoi(newExpr)
if err == nil &&
orchestrator.IsNumber(newExpr) ||
Expand All @@ -185,15 +209,6 @@ func AgregateAgents(agentAg *AgentAgregator) {
agentAg.PublishMessage(exprMsg.ExpressionID, newToken, newExpr)
}

_, err = agentAg.dbConfig.DB.UpdateExpressionData(
context.Background(),
database.UpdateExpressionDataParams{
ID: exprMsg.ExpressionID,
Data: newExpr,
})
if err != nil {
log.Fatalf("Can't update expression data: %v", err)
}
}
}(msgFromAgents)
}
Expand Down
1 change: 1 addition & 0 deletions backend/pkg/orchestrator/get_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func InsertResultToToken(parseExpression, token string, result int) (string, str
}
for ind < len(tokens) {
res = append(res, tokens[ind])
ind++
}
if !isTokenFind {
return "", "", errors.New("can't find token")
Expand Down
10 changes: 7 additions & 3 deletions backend/sql/queries/expressions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ SELECT * FROM expressions;
SELECT * FROM expressions
WHERE id = $1;

-- name: UpdateExpressionData :one
-- name: UpdateExpressionData :exec
UPDATE expressions
SET data = $1
WHERE id = $2
RETURNING *;
WHERE id = $2;

-- name: UpdateExpressionParseData :exec
UPDATE expressions
SET parse_data = $1
WHERE id = $2;

-- name: MakeExpressionReady :exec
UPDATE expressions
Expand Down

0 comments on commit a97d78e

Please sign in to comment.