40 lines
849 B
Go
40 lines
849 B
Go
package workers
|
|
|
|
import (
|
|
"time"
|
|
|
|
"backend/modules/commands/store"
|
|
"backend/providers/storage"
|
|
|
|
_ "git.ipao.vip/rogeecn/atom"
|
|
_ "git.ipao.vip/rogeecn/atom/contracts"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// @provider:except contracts.Initial atom.GroupInitial
|
|
type Controller struct {
|
|
log *logrus.Entry `inject:"false"`
|
|
cmdStore *store.StoreMedias
|
|
storage *storage.Config
|
|
}
|
|
|
|
func (c *Controller) Prepare() error {
|
|
c.log = logrus.WithField("module", "workers.worker")
|
|
c.log.Info("start workers")
|
|
|
|
go c.store()
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c *Controller) store() {
|
|
ticker := time.NewTicker(time.Minute * 60)
|
|
|
|
for range ticker.C {
|
|
c.log.WithField("action", "store").Info("start to run store")
|
|
if err := c.cmdStore.RunE(c.storage.Path); err != nil {
|
|
c.log.WithField("action", "store").WithError(err).Error("run store cmd failed")
|
|
}
|
|
}
|
|
}
|