-
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.
Merge pull request #3 from vpoluyaktov/ffmpeg_progress_refactor
FFMPEG progress reader refactored
- Loading branch information
Showing
28 changed files
with
524 additions
and
256 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
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(config.Instance().GetRepoOwner(), config.Instance().GetRepoName()) | ||
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) | ||
} | ||
} |
Oops, something went wrong.