mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-07-27 17:28:35 +00:00
feat: task can report step and final result
This commit is contained in:
parent
9be39b8cd4
commit
6030610c04
7 changed files with 219 additions and 36 deletions
32
runtime/taskmap.go
Normal file
32
runtime/taskmap.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package runtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var globalTaskMap sync.Map
|
||||
|
||||
// startTask adds the task to global map
|
||||
func startTask(buildID int64, ctx context.Context) error {
|
||||
_, exist := globalTaskMap.Load(buildID)
|
||||
if exist {
|
||||
return fmt.Errorf("task %d already exists", buildID)
|
||||
}
|
||||
|
||||
task := NewTask(buildID)
|
||||
|
||||
// set task ve to global map
|
||||
// when task is done or canceled, it will be removed from the map
|
||||
globalTaskMap.Store(buildID, task)
|
||||
|
||||
go task.Run(ctx)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// finishTask removes the task from global map
|
||||
func finishTask(buildID int64) {
|
||||
globalTaskMap.Delete(buildID)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue