Ask For Task Status Seperatly and logs incrementally

This commit is contained in:
speatzle 2024-05-09 19:09:48 +02:00
parent d185784cd1
commit 12e83aa8d2
4 changed files with 73 additions and 34 deletions

View file

@ -25,7 +25,7 @@ func StartTask(conf config.Config, data types.TaskStart) error {
switch data.Type {
case constants.TASK_TYPE_HEALTHCHECK:
var hData HealthCheckData
var hData types.HealthCheckData
err := json.Unmarshal(data.Data, &hData)
if err != nil {
return fmt.Errorf("Unmarshal Healthcheck Data: %w", err)
@ -49,15 +49,23 @@ func StartTask(conf config.Config, data types.TaskStart) error {
}
}
func Get() []types.Task {
func Get(r types.TaskStatusRequest) (*types.Task, error) {
taskMutex.Lock()
defer taskMutex.Unlock()
t := []types.Task{}
for i := range tasks {
t = append(t, *tasks[i])
t, ok := tasks[r.ID]
if !ok {
return nil, fmt.Errorf("Task does not Exist")
}
return t
res := *t
// Send only new logs if there are any
if len(res.Log) >= r.LogOffset {
res.Log = res.Log[r.LogOffset:]
}
return &res, nil
}
func DeleteTask(id int) error {