Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions pkg/action/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Manager interface {
// Run executes an action in foreground.
Run(ctx context.Context, a *Action) (RunInfo, error)
// RunBackground executes an action in background.
RunBackground(ctx context.Context, a *Action) (RunInfo, chan error)
RunBackground(ctx context.Context, a *Action, runId string) (RunInfo, chan error)
// RunInfoByAction returns all running actions by action id.
RunInfoByAction(aid string) []RunInfo
// RunInfoByID returns an action matching run id.
Expand Down Expand Up @@ -156,12 +156,14 @@ type RunInfo struct {
// @todo add more info for status like error message or exit code. Or have it in output.
}

func (m *actionManagerMap) registerRun(a *Action) RunInfo {
func (m *actionManagerMap) registerRun(a *Action, id string) RunInfo {
// @todo rethink the implementation
m.mxRun.Lock()
defer m.mxRun.Unlock()
if id == "" {
id = strconv.FormatInt(time.Now().Unix(), 10) + "-" + a.ID
}
// @todo validate the action is actually running and the method was not just incorrectly requested
id := strconv.FormatInt(time.Now().Unix(), 10) + "-" + a.ID
ri := RunInfo{
ID: id,
Action: a,
Expand All @@ -182,11 +184,12 @@ func (m *actionManagerMap) updateRunStatus(id string, st string) {

func (m *actionManagerMap) Run(ctx context.Context, a *Action) (RunInfo, error) {
// @todo add the same status change info
return m.registerRun(a), a.Execute(ctx)
return m.registerRun(a, ""), a.Execute(ctx)
}

func (m *actionManagerMap) RunBackground(ctx context.Context, a *Action) (RunInfo, chan error) {
ri := m.registerRun(a)
func (m *actionManagerMap) RunBackground(ctx context.Context, a *Action, runId string) (RunInfo, chan error) {
// @todo change runId to runOptions with possibility to create filestream names in webUI.
ri := m.registerRun(a, runId)
chErr := make(chan error)
go func() {
m.updateRunStatus(ri.ID, "running")
Expand Down