GitRoot
craft your forge, build your project, grow your community freely
1// SPDX-FileCopyrightText: 2025 Romain Maneschi <romain@gitroot.dev>
2//
3// SPDX-License-Identifier: MIT
4
5package model
6
7import "github.com/tidwall/gjson"
8
9type Exec struct {
10 Build string `json:"build"` //image docker, path to Dockerfile
11 Cmds []Cmd `json:"cmds"`
12 Env []string `json:"env"`
13}
14
15type Cmd struct {
16 Cmd string `json:"cmd"`
17 Args []string `json:"args"`
18}
19
20type ExecStatus struct {
21 CmdsExec []string `json:"cmdsExec"`
22 CmdsStatus []int `json:"cmdsStatus"`
23 CmdsLogs []string `json:"cmdsLogs"`
24 CmdsStats []CmdStats `json:"cmdsStats"`
25}
26
27type CmdStats struct {
28 MaxMemoryBytes uint64 `json:"maxMemoryBytes"`
29 MaxThreads int32 `json:"maxThreads"`
30 ReadBytesTotal uint64 `json:"readBytesTotal"`
31 WriteBytesTotal uint64 `json:"writeBytesTotal"`
32 TotalCPUTimeMs uint64 `json:"totalCpuTimeMs"`
33}
34
35func ExecStatusFromString(execStatus string) ExecStatus {
36 jsonStatus := gjson.Parse(execStatus)
37 res := ExecStatus{
38 CmdsExec: []string{},
39 CmdsStatus: []int{},
40 CmdsLogs: []string{},
41 CmdsStats: []CmdStats{},
42 }
43 for _, j := range jsonStatus.Get("cmdsExec").Array() {
44 res.CmdsExec = append(res.CmdsExec, j.String())
45 }
46 for _, j := range jsonStatus.Get("cmdsStatus").Array() {
47 res.CmdsStatus = append(res.CmdsStatus, int(j.Int()))
48 }
49 for _, j := range jsonStatus.Get("cmdsLogs").Array() {
50 res.CmdsLogs = append(res.CmdsLogs, j.String())
51 }
52 for _, j := range jsonStatus.Get("cmdsStats").Array() {
53 res.CmdsStats = append(res.CmdsStats, CmdStats{
54 MaxMemoryBytes: j.Get("maxMemoryBytes").Uint(),
55 MaxThreads: int32(j.Get("maxThreads").Int()),
56 ReadBytesTotal: j.Get("readBytesTotal").Uint(),
57 WriteBytesTotal: j.Get("writeBytesTotal").Uint(),
58 TotalCPUTimeMs: j.Get("totalCpuTimeMs").Uint(),
59 })
60 }
61 return res
62}