MCPcopy
hub / github.com/cortesi/modd / Run

Method Run

daemon.go:36–73  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34}
35
36func (d *daemon) Run() {
37 var lastStart time.Time
38 delay := MinRestart
39 for d.stop != true {
40 if delay > MinRestart {
41 d.log.Notice(">> restart backoff... %dms", delay/time.Millisecond)
42 }
43 if !lastStart.IsZero() {
44 time.Sleep(delay)
45 }
46 d.log.Notice(">> starting...")
47 lastStart = time.Now()
48 err, pstate := d.ex.Run(d.log, false)
49
50 if err != nil {
51 d.log.Shout("execution error: %s", err)
52 } else if pstate.Error != nil {
53 if _, ok := pstate.Error.(*exec.ExitError); ok {
54 d.log.Warn("exited: %s", pstate.ProcState)
55 } else {
56 d.log.Shout("exited: %s", err)
57 }
58 } else {
59 d.log.Warn("exited: %s", pstate.ProcState)
60 }
61
62 // If we exited cleanly, or the process ran for > MaxRestart, we reset
63 // the delay timer
64 if time.Now().Sub(lastStart) > MaxRestart {
65 delay = MinRestart
66 } else {
67 delay *= MulRestart
68 if delay > MaxRestart {
69 delay = MaxRestart
70 }
71 }
72 }
73}
74
75// Restart the daemon, or start it if it's not yet running
76func (d *daemon) Restart() {

Callers 5

RestartMethod · 0.95
TestWatchFunction · 0.45
mainFunction · 0.45
PushMethod · 0.45
PushMethod · 0.45

Calls

no outgoing calls

Tested by 1

TestWatchFunction · 0.36