Skip to content

Commit be4e3c2

Browse files
committed
feat(parser): store hosts in state
1 parent 2e67fc1 commit be4e3c2

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

services/tasks/stage_parsers/ansible_result.go

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,6 @@ func (p AnsibleResultStageParser) IsEnd(currentStage *db.TaskStage, output db.Ta
4343
return strings.TrimSpace(output.Output) == ""
4444
}
4545

46-
//type AnsibleResultHost struct {
47-
// Host string `json:"host"`
48-
// Ok int `json:"ok"`
49-
// Changed int `json:"changed"`
50-
// Unreachable int `json:"unreachable"`
51-
// Failed int `json:"failed"`
52-
// Skipped int `json:"skipped"`
53-
// Rescued int `json:"rescued"`
54-
// Ignored int `json:"ignored"`
55-
//}
56-
5746
var ansibleResultHostRE = regexp.MustCompile(
5847
`^([^\s]+)\s*:\s*` +
5948
`ok=(\d+)\s+` +
@@ -72,7 +61,7 @@ func toInt(s string) int {
7261
}
7362

7463
type AnsibleResultStageParserState struct {
75-
//Hosts []AnsibleResultHost
64+
Hosts []db.AnsibleTaskHost `json:"hosts"`
7665
}
7766

7867
func (p AnsibleResultStageParser) Parse(currentStage *db.TaskStage, output db.TaskOutput, store db.Store, projectID int) (ok bool, err error) {
@@ -105,18 +94,7 @@ func (p AnsibleResultStageParser) Parse(currentStage *db.TaskStage, output db.Ta
10594
return
10695
}
10796

108-
//p.state.Hosts = append(p.state.Hosts, AnsibleResultHost{
109-
// Host: m[1],
110-
// Ok: toInt(m[2]),
111-
// Changed: toInt(m[3]),
112-
// Unreachable: toInt(m[4]),
113-
// Failed: toInt(m[5]),
114-
// Skipped: toInt(m[6]),
115-
// Rescued: toInt(m[7]),
116-
// Ignored: toInt(m[8]),
117-
//})
118-
119-
err = store.CreateAnsibleTaskHost(db.AnsibleTaskHost{
97+
host := db.AnsibleTaskHost{
12098
TaskID: currentStage.TaskID,
12199
ProjectID: projectID,
122100
Host: m[1],
@@ -127,13 +105,18 @@ func (p AnsibleResultStageParser) Parse(currentStage *db.TaskStage, output db.Ta
127105
Skipped: toInt(m[6]),
128106
Rescued: toInt(m[7]),
129107
Ignored: toInt(m[8]),
130-
})
108+
}
109+
110+
p.state.Hosts = append(p.state.Hosts, host)
111+
112+
err = store.CreateAnsibleTaskHost(host)
131113

132114
return
133115
}
134116

135117
func (p AnsibleResultStageParser) Result() (res map[string]any) {
136118
res = make(map[string]any)
119+
p.state.Hosts = make([]db.AnsibleTaskHost, 0)
137120
//res["hosts"] = p.state.Hosts
138121
return
139122
}

0 commit comments

Comments
 (0)