Skip to content

Commit

Permalink
fix: clear
Browse files Browse the repository at this point in the history
  • Loading branch information
whatwewant committed Aug 13, 2024
1 parent 81b7594 commit 5def668
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 192 deletions.
12 changes: 7 additions & 5 deletions cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sync"
"time"

"github.com/go-zoox/cache"
sf "github.com/go-zoox/core-utils/safe"
"github.com/go-zoox/logger"
"github.com/go-zoox/safe"
robCron "github.com/robfig/cron/v3"
Expand All @@ -14,7 +14,7 @@ import (
// Cron is a schedule job, which can be used to run jobs on a schedule.
type Cron struct {
core *robCron.Cron
cache cache.Cache
cache *sf.Map[string, robCron.EntryID]
sync.Mutex

cfg *Config
Expand Down Expand Up @@ -53,7 +53,7 @@ func New(cfg ...*Config) (*Cron, error) {

return &Cron{
core: core,
cache: cache.New(),
cache: sf.NewMap[string, robCron.EntryID](),
cfg: _cfg,
}, nil
}
Expand Down Expand Up @@ -97,7 +97,7 @@ func (c *Cron) AddJob(id string, spec string, job func() error, opts ...AddJobOp
return err
}

if err := c.cache.Set(id, &innerID); err != nil {
if err := c.cache.Set(id, innerID); err != nil {
return err
}

Expand All @@ -107,7 +107,7 @@ func (c *Cron) AddJob(id string, spec string, job func() error, opts ...AddJobOp
// RemoveJob removes a Job from the Cron to be run on the given schedule.
func (c *Cron) RemoveJob(id string) (err error) {
var innerID robCron.EntryID
if err = c.cache.Get(id, &innerID); err != nil {
if innerID := c.cache.Get(id); innerID == 0 {
return
}

Expand All @@ -130,6 +130,8 @@ func (c *Cron) ClearJobs() (err error) {
c.core.Remove(entry.ID)
}

c.cache.Clear()

return
}

Expand Down
23 changes: 8 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
module github.com/go-zoox/cron

go 1.17
go 1.22.1

require (
github.com/go-zoox/cache v1.0.6
github.com/go-zoox/logger v1.2.2
github.com/go-zoox/safe v1.0.1
github.com/go-zoox/core-utils v1.4.11
github.com/go-zoox/logger v1.5.1
github.com/go-zoox/safe v1.2.0
github.com/robfig/cron/v3 v3.0.1
)

require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/go-zoox/chalk v1.0.1 // indirect
github.com/go-zoox/core-utils v1.3.1 // indirect
github.com/go-zoox/datetime v1.1.0 // indirect
github.com/go-zoox/encoding v1.0.5 // indirect
github.com/go-errors/errors v1.5.1 // indirect
github.com/go-zoox/chalk v1.0.2 // indirect
github.com/go-zoox/datetime v1.3.1 // indirect
github.com/go-zoox/errors v1.0.2 // indirect
github.com/go-zoox/fs v1.2.4 // indirect
github.com/go-zoox/kv v1.5.9 // indirect
github.com/go-zoox/uuid v0.0.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
)
Loading

0 comments on commit 5def668

Please sign in to comment.