Added parallel batching, IPMI power cycle, sensors, and console
This commit is contained in:
51
test/batch-test.go
Normal file
51
test/batch-test.go
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/batch"
|
||||
"fmt"
|
||||
"time"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func exampleJob(name string, id int) string {
|
||||
fmt.Printf("[%d] %s started...\n", id, name)
|
||||
time.Sleep(time.Second * 5)
|
||||
fmt.Printf("[%d] %s ending...\n", id, name)
|
||||
return name
|
||||
}
|
||||
|
||||
|
||||
func main() {
|
||||
|
||||
fmt.Printf("GOMAXPROCS=%d\n", runtime.GOMAXPROCS(0))
|
||||
|
||||
jobstorun := 1000
|
||||
|
||||
// create batch pool to run 100 jobs at a time every 10 seconds
|
||||
batchpool := batch.New(100, 10)
|
||||
retvalues := make(chan string, jobstorun)
|
||||
|
||||
// submit a bunch of jobs
|
||||
for i:=0; i<jobstorun; i++ {
|
||||
|
||||
name := fmt.Sprintf("job-%04d", i)
|
||||
id := i;
|
||||
|
||||
batchpool.Submit(func() {
|
||||
retvalues <- exampleJob(name, id)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// Run all batch jobs to completion
|
||||
batchpool.Run()
|
||||
|
||||
close(retvalues)
|
||||
|
||||
for s:= range retvalues {
|
||||
fmt.Printf("Return value is %s\n", s)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user