Move into api routers instead of main
This commit is contained in:
37
services/entry/pkg/infrastructure/dependencies/cron.go
Normal file
37
services/entry/pkg/infrastructure/dependencies/cron.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package dependencies
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/eko/gocache/cache"
|
||||
"github.com/eko/gocache/store"
|
||||
"github.com/go-co-op/gocron"
|
||||
"go.uber.org/zap"
|
||||
"time"
|
||||
)
|
||||
|
||||
func setupCron(l *zap.Logger, cm *cache.MetricCache, cc *client.Client) {
|
||||
l.Info("Setting up job scheduler (cron)")
|
||||
|
||||
s := gocron.NewScheduler(time.UTC)
|
||||
|
||||
s.Every(10).Second().Do(func() {
|
||||
l.Debug("getting container list")
|
||||
list, err := cc.ContainerList(context.Background(), types.ContainerListOptions{})
|
||||
if err != nil {
|
||||
l.Warn(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
err = cm.Set("docker-containers", list, &store.Options{
|
||||
Cost: 2,
|
||||
})
|
||||
if err != nil {
|
||||
l.Warn(err.Error())
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
s.StartAsync()
|
||||
}
|
Reference in New Issue
Block a user