Ask For Task Status Seperatly and logs incrementally
This commit is contained in:
parent
d185784cd1
commit
12e83aa8d2
4 changed files with 73 additions and 34 deletions
20
task/task.go
20
task/task.go
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue