()
| 42 | } |
| 43 | |
| 44 | func (mod *RestAPI) recorder() { |
| 45 | clock := time.Duration(mod.recClock) * time.Second |
| 46 | |
| 47 | mod.recTime = 0 |
| 48 | mod.recording = true |
| 49 | mod.replaying = false |
| 50 | mod.record = recording.New(mod.recordFileName) |
| 51 | |
| 52 | mod.Info("started recording to %s (clock %s) ...", mod.recordFileName, clock) |
| 53 | |
| 54 | mod.recordWait.Add(1) |
| 55 | defer mod.recordWait.Done() |
| 56 | |
| 57 | tick := time.NewTicker(1 * time.Second) |
| 58 | lastSampled := time.Time{} |
| 59 | |
| 60 | for range tick.C { |
| 61 | if !mod.recording { |
| 62 | break |
| 63 | } |
| 64 | |
| 65 | mod.recTime++ |
| 66 | |
| 67 | if time.Since(lastSampled) >= clock { |
| 68 | lastSampled = time.Now() |
| 69 | if err := mod.recordState(); err != nil { |
| 70 | mod.Error("error while recording: %s", err) |
| 71 | mod.recording = false |
| 72 | break |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | mod.Info("stopped recording to %s ...", mod.recordFileName) |
| 78 | } |
| 79 | |
| 80 | func (mod *RestAPI) startRecording(filename string) (err error) { |
| 81 | if mod.recording { |
no test coverage detected