Create Trimmer interface

This commit is contained in:
Sasha Koshka 2024-12-12 18:10:20 -05:00
parent 424eebde84
commit df7c49247b
2 changed files with 11 additions and 3 deletions

View File

@ -225,7 +225,7 @@ func main () {
// set up the trimming routine // set up the trimming routine
trimmer := trimmerRoutine { trimmer := trimmerRoutine {
HTTPHandler: &handler, Trimmer: &handler,
} }
// set up the routine manager // set up the routine manager
@ -266,7 +266,7 @@ func (this *httpServerRoutine) Run (ctx context.Context) error {
} }
type trimmerRoutine struct { type trimmerRoutine struct {
HTTPHandler *stephttp.Handler Trimmer step.Trimmer
} }
func (this *trimmerRoutine) Run (ctx context.Context) error { func (this *trimmerRoutine) Run (ctx context.Context) error {
@ -275,7 +275,7 @@ func (this *trimmerRoutine) Run (ctx context.Context) error {
for { for {
select { select {
case <- ticker.C: case <- ticker.C:
this.HTTPHandler.Trim() this.Trimmer.Trim()
case <- ctx.Done(): case <- ctx.Done():
return ctx.Err() return ctx.Err()
} }

View File

@ -28,6 +28,14 @@ type ConfigProcessor interface {
ProcessConfig (config Meta) error ProcessConfig (config Meta) error
} }
// Trimmer is an object that needs to be routinely "trimmed". This can be
// garbage collecting, sanity checking, etc.
type Trimmer interface {
// Trim trims the object. It must not block for any significant length
// of time. It should be called every minute or so.
Trim ()
}
// FuncProvider provides a template.FuncMap. // FuncProvider provides a template.FuncMap.
type FuncProvider interface { type FuncProvider interface {
Provider Provider