blob: f2fffd417f0342f68c32237d176e39d5ad1748e1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package transcribe
// defaultBreakerLimit is how many episodes may fail in a row before the pass is abandoned.
// Three: enough that a couple of genuinely broken files do not stop the backfill, few enough
// that a misconfiguration costs three episodes rather than the library.
const defaultBreakerLimit = 3
// Breaker stops a recognition pass that is failing for an environmental reason rather than
// because of the episode in front of it.
//
// It exists because of a real failure on the first run: the working directory did not exist, so
// ffmpeg could not write, so every episode failed -- and every failure was recorded as "do not
// try this one again". A misconfigured deploy would have marked the whole backlog attempted in
// seconds and nothing would ever have been transcribed. The same shape as the midroll scan
// marking episodes checked forever after an OutOfMemoryError nobody saw.
//
// Consecutive failures, because one bad file among good ones is the episode's own problem and
// should be marked: the same bytes will fail the same way next time.
type Breaker struct {
// Limit is the number of consecutive failures that abandons the pass. Zero uses the
// default.
Limit int
run int
}
// Failure records a failed episode and reports whether the pass should stop.
func (b *Breaker) Failure() bool {
b.run++
return b.run >= b.limit()
}
// Success records a transcribed episode, which clears the run.
func (b *Breaker) Success() { b.run = 0 }
// Run is how many episodes have failed in a row.
//
// When the pass stops, these are the attempts to give back: they failed for a reason that was
// nothing to do with them, and leaving them marked would hide the episodes for ever.
func (b *Breaker) Run() int { return b.run }
func (b *Breaker) limit() int {
if b.Limit > 0 {
return b.Limit
}
return defaultBreakerLimit
}
|