-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11bd7cf
commit bb7c392
Showing
25 changed files
with
310 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package controller | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/vpoluyaktov/abb_ia/internal/config" | ||
"github.com/vpoluyaktov/abb_ia/internal/dto" | ||
"github.com/vpoluyaktov/abb_ia/internal/logger" | ||
"github.com/vpoluyaktov/abb_ia/internal/mq" | ||
"github.com/vpoluyaktov/abb_ia/internal/utils" | ||
) | ||
|
||
type BootController struct { | ||
mq *mq.Dispatcher | ||
} | ||
|
||
func NewBootController(dispatcher *mq.Dispatcher) *BootController { | ||
c := &BootController{} | ||
c.mq = dispatcher | ||
c.mq.RegisterListener(mq.BootController, c.dispatchMessage) | ||
go c.bootStrap(&dto.BootstrapCommand{}) | ||
return c | ||
} | ||
|
||
func (c *BootController) checkMQ() { | ||
m := c.mq.GetMessage(mq.BootController) | ||
if m != nil { | ||
c.dispatchMessage(m) | ||
} | ||
} | ||
|
||
func (c *BootController) dispatchMessage(m *mq.Message) { | ||
switch dto := m.Dto.(type) { | ||
case *dto.BootstrapCommand: | ||
go c.bootStrap(dto) | ||
default: | ||
m.UnsupportedTypeError(mq.BootController) | ||
} | ||
} | ||
|
||
func (c *BootController) bootStrap(cmd *dto.BootstrapCommand) { | ||
// wait for all components to initialize | ||
time.Sleep(3 * time.Second) | ||
if c.checkFFmpeg() { | ||
c.checkNewVersion() | ||
} | ||
} | ||
|
||
func (c *BootController) checkFFmpeg() bool { | ||
if !(utils.CommandExists("ffmpeg") && utils.CommandExists("ffprobe")) { | ||
logger.Fatal("Bootstrap: ffmpeg or ffprobe command not found") | ||
c.mq.SendMessage(mq.BootController, mq.SearchPage, &dto.FFMPEGNotFoundError{}, true) | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
func (c *BootController) checkNewVersion() { | ||
|
||
latestVersion, err := utils.GetLatestVersion("vpoluyaktov", "abb_ia") | ||
if err != nil { | ||
logger.Error("Can't check new version: " + err.Error()) | ||
return | ||
} | ||
|
||
result, err := utils.CompareVersions(latestVersion, config.Instance().AppVersion()) | ||
if err != nil { | ||
logger.Error("Can not compare versions: " + err.Error()) | ||
return | ||
} | ||
|
||
if result > 0 { | ||
c.mq.SendMessage(mq.BootController, mq.SearchPage, &dto.NewAppVersionFound{CurrentVersion: config.Instance().AppVersion(), NewVersion: latestVersion}, true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.