How to use Info method of runner Package

Best Gauge code snippet using runner.Info

runner.go

Source:runner.go Github

copy

Full Screen

...24type Runner struct {25 tomb tomb.Tomb26 startc chan startReq27 stopc chan string28 donec chan doneInfo29 startedc chan startInfo30 isFatal func(error) bool31 moreImportant func(err0, err1 error) bool32}33type startReq struct {34 id string35 start func() (Worker, error)36}37type startInfo struct {38 id string39 worker Worker40}41type doneInfo struct {42 id string43 err error44}45// NewRunner creates a new Runner. When a worker finishes, if its error46// is deemed fatal (determined by calling isFatal), all the other workers47// will be stopped and the runner itself will finish. Of all the fatal errors48// returned by the stopped workers, only the most important one,49// determined by calling moreImportant, will be returned from50// Runner.Wait. Non-fatal errors will not be returned.51//52// The function isFatal(err) returns whether err is a fatal error. The53// function moreImportant(err0, err1) returns whether err0 is considered54// more important than err1.55func NewRunner(isFatal func(error) bool, moreImportant func(err0, err1 error) bool) *Runner {56 runner := &Runner{57 startc: make(chan startReq),58 stopc: make(chan string),59 donec: make(chan doneInfo),60 startedc: make(chan startInfo),61 isFatal: isFatal,62 moreImportant: moreImportant,63 }64 go func() {65 defer runner.tomb.Done()66 runner.tomb.Kill(runner.run())67 }()68 return runner69}70var ErrDead = errors.New("worker runner is not running")71// StartWorker starts a worker running associated with the given id.72// The startFunc function will be called to create the worker;73// when the worker exits, it will be restarted as long as it74// does not return a fatal error.75//76// If there is already a worker with the given id, nothing will be done.77//78// StartWorker returns ErrDead if the runner is not running.79func (runner *Runner) StartWorker(id string, startFunc func() (Worker, error)) error {80 select {81 case runner.startc <- startReq{id, startFunc}:82 return nil83 case <-runner.tomb.Dead():84 }85 return ErrDead86}87// StopWorker stops the worker associated with the given id.88// It does nothing if there is no such worker.89//90// StopWorker returns ErrDead if the runner is not running.91func (runner *Runner) StopWorker(id string) error {92 select {93 case runner.stopc <- id:94 return nil95 case <-runner.tomb.Dead():96 }97 return ErrDead98}99func (runner *Runner) Wait() error {100 return runner.tomb.Wait()101}102func (runner *Runner) Kill() {103 log.Debugf("worker: killing runner %p", runner)104 runner.tomb.Kill(nil)105}106// Stop kills the given worker and waits for it to exit.107func Stop(worker Worker) error {108 worker.Kill()109 return worker.Wait()110}111type workerInfo struct {112 start func() (Worker, error)113 worker Worker114 restartDelay time.Duration115 stopping bool116}117func (runner *Runner) run() error {118 // workers holds the current set of workers. All workers with a119 // running goroutine have an entry here.120 workers := make(map[string]*workerInfo)121 var finalError error122 // isDying holds whether the runner is currently dying. When it123 // is dying (whether as a result of being killed or due to a124 // fatal error), all existing workers are killed, no new workers125 // will be started, and the loop will exit when all existing126 // workers have stopped.127 isDying := false128 tombDying := runner.tomb.Dying()129 for {130 if isDying && len(workers) == 0 {131 return finalError132 }133 select {134 case <-tombDying:135 log.Infof("worker: runner is dying")136 isDying = true137 killAll(workers)138 tombDying = nil139 case req := <-runner.startc:140 if isDying {141 log.Infof("worker: ignoring start request for %q when dying", req.id)142 break143 }144 info := workers[req.id]145 if info == nil {146 workers[req.id] = &workerInfo{147 start: req.start,148 restartDelay: RestartDelay,149 }150 go runner.runWorker(0, req.id, req.start)151 break152 }153 if !info.stopping {154 // The worker is already running, so leave it alone155 break156 }157 // The worker previously existed and is158 // currently being stopped. When it eventually159 // does stop, we'll restart it immediately with160 // the new start function.161 info.start = req.start162 info.restartDelay = 0163 case id := <-runner.stopc:164 if info := workers[id]; info != nil {165 killWorker(id, info)166 }167 case info := <-runner.startedc:168 workerInfo := workers[info.id]169 workerInfo.worker = info.worker170 if isDying {171 killWorker(info.id, workerInfo)172 }173 case info := <-runner.donec:174 workerInfo := workers[info.id]175 if !workerInfo.stopping && info.err == nil {176 info.err = errors.New("unexpected quit")177 }178 if info.err != nil {179 if runner.isFatal(info.err) {180 log.Errorf("worker: fatal %q: %v", info.id, info.err)181 if finalError == nil || runner.moreImportant(info.err, finalError) {182 finalError = info.err183 }184 delete(workers, info.id)185 if !isDying {186 isDying = true187 killAll(workers)188 }189 break190 } else {191 log.Errorf("worker: exited %q: %v", info.id, info.err)192 }193 }194 if workerInfo.start == nil {195 // The worker has been deliberately stopped;196 // we can now remove it from the list of workers.197 delete(workers, info.id)198 break199 }200 go runner.runWorker(workerInfo.restartDelay, info.id, workerInfo.start)201 workerInfo.restartDelay = RestartDelay202 }203 }204}205func killAll(workers map[string]*workerInfo) {206 for id, info := range workers {207 killWorker(id, info)208 }209}210func killWorker(id string, info *workerInfo) {211 if info.worker != nil {212 log.Debugf("worker: killing %q", id)213 info.worker.Kill()214 info.worker = nil215 }216 info.stopping = true217 info.start = nil218}219// runWorker starts the given worker after waiting for the given delay.220func (runner *Runner) runWorker(delay time.Duration, id string, start func() (Worker, error)) {221 if delay > 0 {222 log.Infof("worker: restarting %q in %v", id, delay)223 select {224 case <-runner.tomb.Dying():225 runner.donec <- doneInfo{id, nil}226 return227 case <-time.After(delay):228 }229 }230 log.Infof("worker: start %q", id)231 worker, err := start()232 if err == nil {233 runner.startedc <- startInfo{id, worker}234 err = worker.Wait()235 }236 runner.donec <- doneInfo{id, err}237}...

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 r := runner.New(3 * time.Second)4 r.Add(createTask(), createTask(), createTask())5 if err := r.Start(); err != nil {6 switch err {7 fmt.Println("Terminating due to timeout")8 os.Exit(1)9 fmt.Println("Terminating due to interrupt")10 os.Exit(2)11 }12 }13 fmt.Println("Process ended")14}15import (16func main() {17 r := runner.New(3 * time.Second)18 r.Add(createTask(), createTask(), createTask())19 if err := r.Start(); err != nil {20 switch err {21 fmt.Println("Terminating due to timeout")22 os.Exit(1)23 fmt.Println("Terminating due to interrupt")24 os.Exit(2)25 }26 }27 fmt.Println("Process ended")28}29import (30func main() {31 r := runner.New(3 * time.Second)32 r.Add(createTask(), createTask(), createTask())33 if err := r.Start(); err != nil {34 switch err {35 fmt.Println("Terminating due to timeout")36 os.Exit(1)37 fmt.Println("Terminating due to interrupt")38 os.Exit(2)39 }40 }41 fmt.Println("Process ended")42}43import (44func main() {45 r := runner.New(3 * time.Second)46 r.Add(createTask(), createTask(), createTask())47 if err := r.Start(); err != nil {48 switch err {49 fmt.Println("Terminating due to timeout")50 os.Exit(1)51 fmt.Println("Terminating due to interrupt")52 os.Exit(2)53 }54 }55 fmt.Println("Process ended")56}

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 r := runner.New(3 * time.Second)4 r.Add(createTask(), createTask(), createTask())5 if err := r.Start(); err != nil {6 switch err {7 fmt.Println("Terminating due to timeout.")8 os.Exit(1)9 fmt.Println("Terminating due to interrupt.")10 os.Exit(2)11 }12 }13 fmt.Println("Process ended.")14}15import (16type Runner struct {17 tasks []func(int)18}19var ErrTimeout = errors.New("received timeout")20var ErrInterrupt = errors.New("received interrupt")21func New(d time.Duration) *Runner {22 return &Runner{23 interrupt: make(chan os.Signal, 1),24 complete: make(chan error),25 timeout: time.After(d),26 }27}28func (r *Runner) Add(tasks ...func(int)) {29 r.tasks = append(r.tasks, tasks...)30}31func (r *Runner) Start() error {32 signal.Notify(r.interrupt, os.Interrupt)33 go func() {34 r.complete <- r.run()35 }()36 select {37 }38}

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(runner.Info())4}5import (6func main() {7 fmt.Println(runner.Info())8}

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(runner.Info())4}5import (6func main() {7 fmt.Println(runner.Info())8}9import (10func main() {11 fmt.Println(runner.Info())12}13import (14func main() {15 fmt.Println(runner.Info())16}17import (18func main() {19 fmt.Println(runner.Info())20}21import (22func main() {23 fmt.Println(runner.Info())24}25import (26func main() {27 fmt.Println(runner.Info())28}29import (30func main() {31 fmt.Println(runner.Info())32}33import (34func main() {35 fmt.Println(runner.Info())36}37import (38func main() {39 fmt.Println(runner.Info())40}41import (42func main() {43 fmt.Println(runner.Info())44}

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "github.com/runner"3func main() {4 fmt.Println("This is main")5 r := runner.NewRunner()6 r.Info()7}8import "fmt"9import "github.com/runner"10func main() {11 fmt.Println("This is main")12 r := runner.NewRunner()13 r.Info()14}15import "fmt"16import "github.com/runner"17func main() {18 fmt.Println("This is main")19 r := runner.NewRunner()20 r.Info()21}22import "fmt"23import "github.com/runner"24func main() {25 fmt.Println("This is main")26 r := runner.NewRunner()27 r.Info()28}29import "fmt"30import "github.com/runner"31func main() {32 fmt.Println("This is main")33 r := runner.NewRunner()34 r.Info()35}36import "fmt"37import "github.com/runner"38func main() {39 fmt.Println("This is main")40 r := runner.NewRunner()41 r.Info()42}43import "fmt"44import "github.com/runner"45func main() {46 fmt.Println("This is main")47 r := runner.NewRunner()48 r.Info()49}50import "fmt"51import "github.com/runner"52func main() {53 fmt.Println("This is main")54 r := runner.NewRunner()55 r.Info()56}57import "fmt"58import "github.com/runner"59func main() {60 fmt.Println("This is main")61 r := runner.NewRunner()62 r.Info()63}

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "runner"3func main() {4 r := runner.New()5 r.Info()6}7import "fmt"8import "runner"9func main() {10 r := runner.New()11 r.Runner()12}13import "fmt"14import "runner"15func main() {16 r := runner.New()17 r.Runner()18}19import "fmt"20import "runner"21func main() {22 r := runner.New()23 r.Runner()24}25import "fmt"26import "runner"27func main() {28 r := runner.New()29 r.Runner()30}

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "github.com/runner"3func main() {4 runner.Info()5}6func info() {7 fmt.Println("Running...")8}9func info() {10 fmt.Println("Running...")11}12func Info() {13 info()14}

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "github.com/Go-Web-Dev/Go-Web-Dev-1/runner"3func main() {4r := runner.New(10 * time.Second)5r.Add(createTask(), createTask(), createTask())6if err := r.Start(); err != nil {7switch err {8fmt.Println("Terminating due to timeout.")9os.Exit(1)10fmt.Println("Terminating due to interrupt.")11os.Exit(2)12}13}14}15func createTask() func(int) {16return func(id int) {17time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond)18}19}20import (21func main() {22r := runner.New(3 * time.Second)23r.Add(createTask(), createTask(), createTask())24if err := r.Start(); err != nil {25switch err {26fmt.Println("Terminating due to timeout.")27os.Exit(1)28fmt.Println("Terminating due to interrupt.")29os.Exit(2)30}31}32}33func createTask() func(int) {34return func(id int) {35time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond)36}37}38import (39func main() {40r := runner.New(3 * time.Second)41r.Add(createTask(), createTask(), createTask())42if err := r.Start(); err != nil {43switch err {44fmt.Println("Terminating due to timeout.")45os.Exit(1)46fmt.Println("Terminating due to interrupt.")47os.Exit(2)48}49}50}51func createTask() func(int) {52return func(id int) {53time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond)54}55}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful