feat(cron): add cron scheduler
This commit is contained in:
parent
0dfa09033e
commit
0962ddb57c
4 changed files with 32 additions and 12 deletions
19
src/cron/wrapper.go
Normal file
19
src/cron/wrapper.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package cron
|
||||
|
||||
import cronv3 "github.com/robfig/cron/v3"
|
||||
|
||||
type ICron interface {
|
||||
AddFun(spec string, cmd func()) error
|
||||
Start()
|
||||
Stop()
|
||||
}
|
||||
|
||||
type MyCron struct {
|
||||
*cronv3.Cron
|
||||
}
|
||||
|
||||
func NewMyCron() *MyCron {
|
||||
return &MyCron{
|
||||
Cron: cronv3.New(),
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import (
|
|||
"github.com/ihexxa/gocfg"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/ihexxa/quickshare/src/cron"
|
||||
"github.com/ihexxa/quickshare/src/cryptoutil"
|
||||
"github.com/ihexxa/quickshare/src/db/boltstore"
|
||||
"github.com/ihexxa/quickshare/src/db/fileinfostore"
|
||||
|
@ -36,6 +37,7 @@ type Deps struct {
|
|||
limiter iolimiter.ILimiter
|
||||
workers worker.IWorkerPool
|
||||
boltStore *boltstore.BoltStore
|
||||
cron cron.ICron
|
||||
}
|
||||
|
||||
func NewDeps(cfg gocfg.ICfg) *Deps {
|
||||
|
@ -129,3 +131,11 @@ func (deps *Deps) BoltStore() *boltstore.BoltStore {
|
|||
func (deps *Deps) SetBoltStore(boltStore *boltstore.BoltStore) {
|
||||
deps.boltStore = boltStore
|
||||
}
|
||||
|
||||
func (deps *Deps) Cron() cron.ICron {
|
||||
return deps.cron
|
||||
}
|
||||
|
||||
func (deps *Deps) SetCron(cronImp cron.ICron) {
|
||||
deps.cron = cronImp
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue