Skip to content

Commit 99edb66

Browse files
Parameter for run Id (#55)
1 parent 7e1098b commit 99edb66

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

pkg/action/manager.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type Manager interface {
4040
// Run executes an action in foreground.
4141
Run(ctx context.Context, a *Action) (RunInfo, error)
4242
// RunBackground executes an action in background.
43-
RunBackground(ctx context.Context, a *Action) (RunInfo, chan error)
43+
RunBackground(ctx context.Context, a *Action, runId string) (RunInfo, chan error)
4444
// RunInfoByAction returns all running actions by action id.
4545
RunInfoByAction(aid string) []RunInfo
4646
// RunInfoByID returns an action matching run id.
@@ -156,12 +156,14 @@ type RunInfo struct {
156156
// @todo add more info for status like error message or exit code. Or have it in output.
157157
}
158158

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

183185
func (m *actionManagerMap) Run(ctx context.Context, a *Action) (RunInfo, error) {
184186
// @todo add the same status change info
185-
return m.registerRun(a), a.Execute(ctx)
187+
return m.registerRun(a, ""), a.Execute(ctx)
186188
}
187189

188-
func (m *actionManagerMap) RunBackground(ctx context.Context, a *Action) (RunInfo, chan error) {
189-
ri := m.registerRun(a)
190+
func (m *actionManagerMap) RunBackground(ctx context.Context, a *Action, runId string) (RunInfo, chan error) {
191+
// @todo change runId to runOptions with possibility to create filestream names in webUI.
192+
ri := m.registerRun(a, runId)
190193
chErr := make(chan error)
191194
go func() {
192195
m.updateRunStatus(ri.ID, "running")

0 commit comments

Comments
 (0)