Skip to content

Commit

Permalink
delete olf agents after rebooting http-server
Browse files Browse the repository at this point in the history
  • Loading branch information
Prrromanssss committed Apr 21, 2024
1 parent 8dde176 commit 2903061
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 78 deletions.
1 change: 0 additions & 1 deletion backend/cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/Prrromanssss/DAEE-fullstack/internal/storage"
)

// TODO: Delete privous agents
func main() {
ctxWithCancel, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down
6 changes: 6 additions & 0 deletions backend/cmd/orchestrator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ func main() {
// Configuration Storage
dbCfg := storage.NewStorage(log, cfg.StorageURL)

// Delete terminated agents
err := dbCfg.Queries.TerminateOldAgents(ctxWithCancel)
if err != nil {
log.Warn("can't delete old agents")
}

// Configuration Orchestrator
application, err := orchestratorapp.New(log, cfg, dbCfg, cancel)
if err != nil {
Expand Down
12 changes: 0 additions & 12 deletions backend/internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,6 @@ func NewAgent(
}, nil
}

// DeletePreviousAgents deletes previous agents when the application is restarted.
func (a *Agent) DeletePreviousAgents(ctx context.Context) error {
err := a.dbConfig.Queries.DeleteAgents(ctx)
if err != nil {
a.log.Error("can't delete previous agents", sl.Err(err))

return err
}

return nil
}

// GetSafelyNumberOfActiveCalculations gets NumberOfActiveCalculations with Lock.
func (a *Agent) GetSafelyNumberOfActiveCalculations() int32 {
a.mu.Lock()
Expand Down
42 changes: 10 additions & 32 deletions backend/internal/storage/postgres/agents.sql.go

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

16 changes: 0 additions & 16 deletions backend/internal/storage/postgres/expressions.sql.go

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

17 changes: 5 additions & 12 deletions backend/sql/queries/agents.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ SELECT
FROM agents
ORDER BY created_at DESC;

-- name: GetAgentByID :one
SELECT
agent_id, number_of_parallel_calculations,
last_ping, status, created_at,
number_of_active_calculations
FROM agents
WHERE agent_id = $1;

-- name: UpdateAgentLastPing :exec
UPDATE agents
SET last_ping = $1
Expand All @@ -39,9 +31,6 @@ UPDATE agents
SET status = 'terminated', number_of_active_calculations = 0
WHERE agent_id = $1;

-- name: DeleteAgents :exec
DELETE FROM agents;

-- name: DecrementNumberOfActiveCalculations :exec
UPDATE agents
SET number_of_active_calculations = number_of_active_calculations - 1
Expand All @@ -56,4 +45,8 @@ WHERE agent_id = $1;
UPDATE agents
SET status = 'terminated', number_of_active_calculations = 0
WHERE EXTRACT(SECOND FROM NOW()::timestamp - agents.last_ping) > $1::numeric
RETURNING agent_id;
RETURNING agent_id;

-- name: TerminateOldAgents :exec
DELETE FROM agents
WHERE status = 'terminated';
5 changes: 0 additions & 5 deletions backend/sql/queries/expressions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ SELECT
FROM expressions
WHERE expression_id = $1;

-- name: UpdateExpressionData :exec
UPDATE expressions
SET data = $1
WHERE expression_id = $2;

-- name: UpdateExpressionParseData :exec
UPDATE expressions
SET parse_data = $1
Expand Down

0 comments on commit 2903061

Please sign in to comment.