Skip to content

Commit

Permalink
add reload expressions after server is down, sorting expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Prrromanssss committed Feb 18, 2024
1 parent 41ad638 commit 9617b40
Show file tree
Hide file tree
Showing 15 changed files with 128,276 additions and 30 deletions.
Binary file modified backend/cmd/daee/main
Binary file not shown.
7 changes: 3 additions & 4 deletions backend/cmd/daee/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/Prrromanssss/DAEE-fullstack/handlers"
"github.com/Prrromanssss/DAEE-fullstack/pkg/agent"
"github.com/Prrromanssss/DAEE-fullstack/pkg/logcleaner"
"github.com/Prrromanssss/DAEE-fullstack/pkg/reload"

"github.com/go-chi/chi"
"github.com/go-chi/cors"
Expand Down Expand Up @@ -77,9 +78,7 @@ func main() {

go agent.AgregateAgents(agentAgregator)

if err != nil {
log.Fatalf("Can't connect to RabbitMQ: %v", err)
}
reload.ReloadComputingExpressions(dbCfg, agentAgregator)

// Create operation
config.ConfigOperation(dbCfg)
Expand All @@ -90,7 +89,7 @@ func main() {
dbCfg,
queueForSendToAgentsString,
queueForConsumeFromAgentsString,
5,
2,
)
if err != nil {
log.Fatalf("Can't create agent: %v", err)
Expand Down
128,184 changes: 128,172 additions & 12 deletions backend/daee.log

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions backend/internal/database/agents.sql.go

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

39 changes: 39 additions & 0 deletions backend/internal/database/expressions.sql.go

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

1 change: 1 addition & 0 deletions backend/internal/database/operations.sql.go

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

23 changes: 19 additions & 4 deletions backend/pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ func (a *Agent) DecrementActiveComputers() error {
if err != nil {
return fmt.Errorf("can't update agent status: %v", err)
}
} else {
a.status = "running"
err := a.dbConfig.DB.UpdateAgentStatus(
context.Background(),
database.UpdateAgentStatusParams{
Status: "running",
ID: a.agentID,
})
if err != nil {
return fmt.Errorf("can't update agent status: %v", err)
}
}
return nil
}
Expand Down Expand Up @@ -256,8 +267,8 @@ func (a *Agent) ConsumeMessageFromComputers(result *ExpressionMessage) {
if err != nil {
err := a.Reconnect()
if err != nil {
a.kill <- struct{}{}
log.Printf("Agent Error: %v", err)
a.kill <- struct{}{}
return
}
err = a.PublishMessage(result)
Expand Down Expand Up @@ -285,9 +296,13 @@ func (a *Agent) ConsumeMessageFromAgentAgregator(msgFromAgentAgregator amqp.Deli
return
}

a.mu.Lock()
if a.number_of_active_calculations >= a.number_of_parallel_calculations {
msgFromAgentAgregator.Nack(false, true)
a.mu.Unlock()
return
}
a.mu.Unlock()

err := msgFromAgentAgregator.Ack(false)
if err != nil {
Expand All @@ -298,22 +313,22 @@ func (a *Agent) ConsumeMessageFromAgentAgregator(msgFromAgentAgregator amqp.Deli

err = a.MakeExpressionStatusComputing(&exprMsg)
if err != nil {
a.kill <- struct{}{}
log.Printf("Agent Error: %v", err)
a.kill <- struct{}{}
return
}

err = a.RunSimpleComputer(&exprMsg)
if err != nil {
a.kill <- struct{}{}
log.Printf("Agent Error: %v", err)
a.kill <- struct{}{}
return
}

err = a.ChangeAgentStatusToRunningOrSleeping()
if err != nil {
a.kill <- struct{}{}
log.Printf("Agent Error: %v", err)
a.kill <- struct{}{}
return
}
}
Expand Down
24 changes: 24 additions & 0 deletions backend/pkg/reload/reload_orchestrator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package reload

import (
"context"
"fmt"

"github.com/Prrromanssss/DAEE-fullstack/config"
"github.com/Prrromanssss/DAEE-fullstack/pkg/agent"
)

func ReloadComputingExpressions(dbCfg *config.DBConfig, agentAgr *agent.AgentAgregator) error {
expressions, err := dbCfg.DB.GetComputingExpressions(context.Background())
if err != nil {
return fmt.Errorf("orhestrator Error: %v", err)
}
for _, expr := range expressions {
msgToQueue := agent.MessageFromOrchestrator{
ExpressionID: expr.ID,
Expression: expr.ParseData,
}
agentAgr.AddTask(msgToQueue)
}
return nil
}
3 changes: 2 additions & 1 deletion backend/sql/queries/agents.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ VALUES ($1, $2, $3, $4, $5)
RETURNING *;

-- name: GetAgents :many
SELECT * FROM agents;
SELECT * FROM agents
ORDER BY created_at DESC;

-- name: GetAgentByID :one
SELECT * FROM agents
Expand Down
10 changes: 8 additions & 2 deletions backend/sql/queries/expressions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ VALUES ($1, $2, $3, $4, $5, $6)
RETURNING *;

-- name: GetExpressions :many
SELECT * FROM expressions;
SELECT * FROM expressions
ORDER BY created_at DESC;

-- name: GetExpressionByID :one
SELECT * FROM expressions
Expand All @@ -28,4 +29,9 @@ WHERE id = $4;
-- name: UpdateExpressionStatus :exec
UPDATE expressions
SET status = $1
WHERE id = $2;
WHERE id = $2;

-- name: GetComputingExpressions :many
SELECT * FROM expressions
WHERE status = 'computing'
ORDER BY created_at DESC;
4 changes: 2 additions & 2 deletions backend/sql/queries/operations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ INSERT INTO operations (id, operation_type, execution_time)
VALUES ($1, $2, $3)
RETURNING *;


-- name: UpdateOperationTime :one
UPDATE operations
SET execution_time = $1
WHERE operation_type = $2
RETURNING *;

-- name: GetOperations :many
SELECT * FROM operations;
SELECT * FROM operations
ORDER BY operation_type DESC;

-- name: GetOperationTimeByType :one
SELECT execution_time FROM operations
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/AgentBlock/AgentBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const AgentBlock = ({ agent }: AgentBlockProps) => {
Number of parallel calculations: {agent.number_of_parallel_calculations}
</p>
<p className={styles.text}>
Дата создания: {createdAt}
Created at: {createdAt}
</p>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const ExpressionBlock = ({ expression }: ExpressionBlockProps) => {
</p>
</div>
<p className={styles.createdAt}>
Дата создания: {date}
Created at: {date}
</p>
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/OperationBlock/OperationBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const OperationBlock = ({ operation, saveChanges }: OperationBlockProps)

return (
<div>
<p className={styles.title}>Тип операции (сек): {operation.operation_type}</p>
<p className={styles.title}>Operation type (sec): {operation.operation_type}</p>
<div className={styles.block}>
<Input
type="number"
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/ts/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export const ICONS = {
[AGENT_STATUS.SLEEPING]: greenIcon,
[AGENT_STATUS.WAITING]: yellowIcon,
[AGENT_STATUS.TERMINATED]: redIcon,
[EXPRESSION_STATUS.READY_FOR_COMPUTATION]: blackIcon,
[EXPRESSION_STATUS.READY_FOR_COMPUTATION]: yellowIcon,
[EXPRESSION_STATUS.RESULT]: greenIcon,
[EXPRESSION_STATUS.COMPUTING]: yellowIcon,
[EXPRESSION_STATUS.COMPUTING]: blackIcon,
} as const;

export const AGENT_DESCRIPTION = {
Expand Down

0 comments on commit 9617b40

Please sign in to comment.