refactor foundry lib structure; add transport classes for db,http,websocket; add action interface instead of multiple function that accepts action classes; add changing foundry status on websocket responses
This commit is contained in:
37
internal/foundry/actions/progress.go
Normal file
37
internal/foundry/actions/progress.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/transport"
|
||||
"gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/types"
|
||||
)
|
||||
|
||||
type WsProgressMsg struct {
|
||||
Id string `json:"id"`
|
||||
Message string `json:"message"`
|
||||
Pct float64 `json:"pct"`
|
||||
HasChanged bool `json:"hasChanged,omitempty"`
|
||||
Act string `json:"action"`
|
||||
Step string `json:"step"`
|
||||
}
|
||||
|
||||
func (msg WsProgressMsg) Action(tr *transport.FoundryTransport, status *types.FoundryStatus) error {
|
||||
if !msg.HasChanged {
|
||||
tr.Logger.Debug("World has been launched", "world", msg.Id)
|
||||
select {
|
||||
case <-tr.ExchangeChan.ProgressMsg[msg.Id]:
|
||||
tr.Logger.Warn("Channel for the world is closed", "world", msg.Id)
|
||||
default:
|
||||
close(tr.ExchangeChan.ProgressMsg[msg.Id])
|
||||
}
|
||||
|
||||
if status.IsActive != true {
|
||||
newStatus, err := tr.Http.GetStatus()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
status.Update(newStatus)
|
||||
tr.Logger.Info("Status has been changed", "status", status)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user