Skip to content

Commit 01c44a4

Browse files
authored
deps: update gocron v1 -> v2 (#4317)
1 parent a3dbe7f commit 01c44a4

5 files changed

Lines changed: 65 additions & 38 deletions

File tree

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ require (
3636
github.com/fsnotify/fsnotify v1.9.0
3737
github.com/gin-contrib/gzip v1.2.3
3838
github.com/gin-gonic/gin v1.10.0
39-
github.com/go-co-op/gocron v1.37.0
39+
github.com/go-co-op/gocron/v2 v2.19.1
4040
github.com/go-openapi/errors v0.22.2
4141
github.com/go-openapi/strfmt v0.23.0
4242
github.com/go-openapi/swag v0.23.1
@@ -169,6 +169,7 @@ require (
169169
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
170170
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
171171
github.com/jackc/pgtype v1.14.0 // indirect
172+
github.com/jonboulle/clockwork v0.5.0 // indirect
172173
github.com/josharian/intern v1.0.0 // indirect
173174
github.com/json-iterator/go v1.1.12 // indirect
174175
github.com/kaptinlin/go-i18n v0.1.4 // indirect
@@ -232,7 +233,6 @@ require (
232233
go.opentelemetry.io/otel v1.36.0 // indirect
233234
go.opentelemetry.io/otel/metric v1.36.0 // indirect
234235
go.opentelemetry.io/otel/trace v1.36.0 // indirect
235-
go.uber.org/atomic v1.10.0 // indirect
236236
go.yaml.in/yaml/v2 v2.4.2 // indirect
237237
golang.org/x/arch v0.15.0 // indirect
238238
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect

go.sum

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
125125
github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo5vtkx0=
126126
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
127127
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
128-
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
129128
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
130129
github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
131130
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
@@ -180,8 +179,8 @@ github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E
180179
github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0=
181180
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
182181
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
183-
github.com/go-co-op/gocron v1.37.0 h1:ZYDJGtQ4OMhTLKOKMIch+/CY70Brbb1dGdooLEhh7b0=
184-
github.com/go-co-op/gocron v1.37.0/go.mod h1:3L/n6BkO7ABj+TrfSVXLRzsP26zmikL4ISkLQ0O8iNY=
182+
github.com/go-co-op/gocron/v2 v2.19.1 h1:B4iLeA0NB/2iO3EKQ7NfKn5KsQgZfjb2fkvoZJU3yBI=
183+
github.com/go-co-op/gocron/v2 v2.19.1/go.mod h1:5lEiCKk1oVJV39Zg7/YG10OnaVrDAV5GGR6O0663k6U=
185184
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
186185
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
187186
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
@@ -258,7 +257,6 @@ github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17k
258257
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
259258
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
260259
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
261-
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
262260
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
263261
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
264262
github.com/google/winops v0.0.0-20230712152054-af9b550d0601 h1:XvlrmqZIuwxuRE88S9mkxX+FkV+YakqbiAC5Z4OzDnM=
@@ -351,6 +349,8 @@ github.com/jedib0t/go-pretty/v6 v6.6.7 h1:m+LbHpm0aIAPLzLbMfn8dc3Ht8MW7lsSO4MPIt
351349
github.com/jedib0t/go-pretty/v6 v6.6.7/go.mod h1:YwC5CE4fJ1HFUDeivSV1r//AmANFHyqczZk+U6BDALU=
352350
github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c=
353351
github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo=
352+
github.com/jonboulle/clockwork v0.5.0 h1:Hyh9A8u51kptdkR+cqRpT1EebBwTn1oK9YfGYbdFz6I=
353+
github.com/jonboulle/clockwork v0.5.0/go.mod h1:3mZlmanh0g2NDKO5TWZVJAfofYk64M7XN3SzBPjZF60=
354354
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
355355
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
356356
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
@@ -375,8 +375,6 @@ github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgSh
375375
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
376376
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
377377
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
378-
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
379-
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
380378
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
381379
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
382380
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
@@ -471,7 +469,6 @@ github.com/petar-dambovaliev/aho-corasick v0.0.0-20250424160509-463d218d4745/go.
471469
github.com/pierrec/lz4/v4 v4.1.15/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
472470
github.com/pierrec/lz4/v4 v4.1.18 h1:xaKrnTkyoqfh1YItXl56+6KJNVYWlEEPuAQW9xsplYQ=
473471
github.com/pierrec/lz4/v4 v4.1.18/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
474-
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
475472
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
476473
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
477474
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -499,8 +496,6 @@ github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUc
499496
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
500497
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
501498
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
502-
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
503-
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
504499
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
505500
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
506501
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
@@ -556,7 +551,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
556551
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
557552
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
558553
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
559-
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
560554
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
561555
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
562556
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
@@ -632,9 +626,6 @@ go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
632626
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
633627
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
634628
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
635-
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
636-
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
637-
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
638629
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
639630
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
640631
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=

pkg/apiserver/apiserver.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"time"
1616

1717
"github.com/gin-gonic/gin"
18-
"github.com/go-co-op/gocron"
18+
"github.com/go-co-op/gocron/v2"
1919
log "github.com/sirupsen/logrus"
2020
"gopkg.in/tomb.v2"
2121

@@ -36,7 +36,7 @@ type APIServer struct {
3636
cfg *csconfig.LocalApiServerCfg
3737
dbClient *database.Client
3838
controller *controllers.Controller
39-
flushScheduler *gocron.Scheduler
39+
flushScheduler gocron.Scheduler
4040
router *gin.Engine
4141
httpServer *http.Server
4242
apic *apic
@@ -116,7 +116,7 @@ func CustomRecoveryWithWriter(c *gin.Context) {
116116
// NewServer creates a LAPI server.
117117
// It sets up a gin router, a database client, and a controller.
118118
func NewServer(ctx context.Context, config *csconfig.LocalApiServerCfg, accessLogger *log.Entry) (*APIServer, error) {
119-
var flushScheduler *gocron.Scheduler
119+
var flushScheduler gocron.Scheduler
120120

121121
if accessLogger == nil {
122122
accessLogger = log.StandardLogger().WithFields(nil)
@@ -461,7 +461,7 @@ func (s *APIServer) Close() {
461461
s.dbClient.Ent.Close()
462462

463463
if s.flushScheduler != nil {
464-
s.flushScheduler.Stop()
464+
_ = s.flushScheduler.Shutdown()
465465
}
466466
}
467467

pkg/database/flush.go

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import (
66
"fmt"
77
"time"
88

9-
"github.com/go-co-op/gocron"
10-
log "github.com/sirupsen/logrus"
9+
"github.com/go-co-op/gocron/v2"
1110

1211
"github.com/crowdsecurity/go-cs-lib/cstime"
1312

@@ -19,6 +18,7 @@ import (
1918
"github.com/crowdsecurity/crowdsec/pkg/database/ent/event"
2019
"github.com/crowdsecurity/crowdsec/pkg/database/ent/machine"
2120
"github.com/crowdsecurity/crowdsec/pkg/database/ent/metric"
21+
"github.com/crowdsecurity/crowdsec/pkg/logging"
2222
"github.com/crowdsecurity/crowdsec/pkg/types"
2323
)
2424

@@ -28,7 +28,7 @@ const (
2828
flushInterval = 1 * time.Minute
2929
)
3030

31-
func (c *Client) StartFlushScheduler(ctx context.Context, config *csconfig.FlushDBCfg) (*gocron.Scheduler, error) {
31+
func (c *Client) StartFlushScheduler(ctx context.Context, config *csconfig.FlushDBCfg) (gocron.Scheduler, error) {
3232
maxItems := 0
3333

3434
if config.MaxItems != nil && *config.MaxItems <= 0 {
@@ -40,14 +40,23 @@ func (c *Client) StartFlushScheduler(ctx context.Context, config *csconfig.Flush
4040
}
4141

4242
// Init & Start cronjob every minute for alerts
43-
scheduler := gocron.NewScheduler(time.UTC)
43+
scheduler, err := gocron.NewScheduler(
44+
gocron.WithLocation(time.UTC),
45+
gocron.WithLogger(logging.GoCronLoggerAdapter{Logger: c.Log}),
46+
)
47+
if err != nil {
48+
return nil, err
49+
}
4450

45-
job, err := scheduler.Every(1).Minute().Do(c.FlushAlerts, ctx, time.Duration(config.MaxAge), maxItems)
51+
_, err = scheduler.NewJob(
52+
gocron.DurationJob(1*time.Minute),
53+
gocron.NewTask(c.FlushAlerts, ctx, time.Duration(config.MaxAge), maxItems),
54+
gocron.WithSingletonMode(gocron.LimitModeReschedule),
55+
)
4656
if err != nil {
4757
return nil, fmt.Errorf("while starting FlushAlerts scheduler: %w", err)
4858
}
4959

50-
job.SingletonMode()
5160
// Init & Start cronjob every hour for bouncers/agents
5261
if config.AgentsGC != nil {
5362
if config.AgentsGC.Cert != nil {
@@ -69,7 +78,7 @@ func (c *Client) StartFlushScheduler(ctx context.Context, config *csconfig.Flush
6978
}
7079

7180
if config.AgentsGC.Api != nil {
72-
log.Warning("agents auto-delete for API auth is not supported (use cert or login_password)")
81+
c.Log.Warning("agents auto-delete for API auth is not supported (use cert or login_password)")
7382
}
7483
}
7584

@@ -93,32 +102,38 @@ func (c *Client) StartFlushScheduler(ctx context.Context, config *csconfig.Flush
93102
}
94103

95104
if config.BouncersGC.LoginPassword != nil {
96-
log.Warning("bouncers auto-delete for login/password auth is not supported (use cert or api)")
105+
c.Log.Warning("bouncers auto-delete for login/password auth is not supported (use cert or api)")
97106
}
98107
}
99108

100-
baJob, err := scheduler.Every(flushInterval).Do(c.FlushAgentsAndBouncers, ctx, config.AgentsGC, config.BouncersGC)
109+
_, err = scheduler.NewJob(
110+
gocron.DurationJob(flushInterval),
111+
gocron.NewTask(c.FlushAgentsAndBouncers, ctx, config.AgentsGC, config.BouncersGC),
112+
gocron.WithSingletonMode(gocron.LimitModeReschedule),
113+
)
101114
if err != nil {
102115
return nil, fmt.Errorf("while starting FlushAgentsAndBouncers scheduler: %w", err)
103116
}
104117

105-
baJob.SingletonMode()
106-
107-
metricsJob, err := scheduler.Every(flushInterval).Do(c.flushMetrics, ctx, time.Duration(config.MetricsMaxAge))
118+
_, err = scheduler.NewJob(
119+
gocron.DurationJob(flushInterval),
120+
gocron.NewTask(c.flushMetrics, ctx, time.Duration(config.MetricsMaxAge)),
121+
gocron.WithSingletonMode(gocron.LimitModeReschedule),
122+
)
108123
if err != nil {
109124
return nil, fmt.Errorf("while starting flushMetrics scheduler: %w", err)
110125
}
111126

112-
metricsJob.SingletonMode()
113-
114-
allowlistsJob, err := scheduler.Every(flushInterval).Do(c.flushAllowlists, ctx)
127+
_, err = scheduler.NewJob(
128+
gocron.DurationJob(flushInterval),
129+
gocron.NewTask(c.flushAllowlists, ctx),
130+
gocron.WithSingletonMode(gocron.LimitModeReschedule),
131+
)
115132
if err != nil {
116133
return nil, fmt.Errorf("while starting FlushAllowlists scheduler: %w", err)
117134
}
118135

119-
allowlistsJob.SingletonMode()
120-
121-
scheduler.StartAsync()
136+
scheduler.Start()
122137

123138
return scheduler, nil
124139
}
@@ -211,7 +226,7 @@ func (c *Client) flushAgents(ctx context.Context, authType string, duration *tim
211226
}
212227

213228
func (c *Client) FlushAgentsAndBouncers(ctx context.Context, agentsCfg *csconfig.AuthGCCfg, bouncersCfg *csconfig.AuthGCCfg) error {
214-
log.Debug("starting FlushAgentsAndBouncers")
229+
c.Log.Debug("starting FlushAgentsAndBouncers")
215230

216231
if agentsCfg != nil {
217232
c.flushAgents(ctx, types.TlsAuthType, agentsCfg.CertDuration)

pkg/logging/cronlogger.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package logging
2+
3+
type GoCronLoggerAdapter struct {
4+
Logger ExtLogger
5+
}
6+
7+
func (a GoCronLoggerAdapter) Debug(msg string, args ...any) {
8+
a.Logger.Debug(append([]any{msg}, args...)...)
9+
}
10+
11+
func (a GoCronLoggerAdapter) Info(msg string, args ...any) {
12+
a.Logger.Info(append([]any{msg}, args...)...)
13+
}
14+
15+
func (a GoCronLoggerAdapter) Warn(msg string, args ...any) {
16+
a.Logger.Warn(append([]any{msg}, args...)...)
17+
}
18+
19+
func (a GoCronLoggerAdapter) Error(msg string, args ...any) {
20+
a.Logger.Error(append([]any{msg}, args...)...)
21+
}

0 commit comments

Comments
 (0)