Skip to content

Commit

Permalink
Switch from github.com/robfig/cron/v3 to github.com/dsh2dsh/cron/v3
Browse files Browse the repository at this point in the history
  • Loading branch information
dsh2dsh committed May 1, 2024
1 parent 2406d59 commit 63b4fe1
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 29 deletions.
2 changes: 1 addition & 1 deletion daemon/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"os"
"time"

"github.com/dsh2dsh/cron/v3"
"github.com/prometheus/client_golang/prometheus"
"github.com/robfig/cron/v3"

"github.com/zrepl/zrepl/daemon/job"
"github.com/zrepl/zrepl/daemon/nethelpers"
Expand Down
2 changes: 1 addition & 1 deletion daemon/cron.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package daemon

import (
"github.com/robfig/cron/v3"
"github.com/dsh2dsh/cron/v3"

"github.com/zrepl/zrepl/logger"
)
Expand Down
26 changes: 10 additions & 16 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"syscall"
"time"

"github.com/dsh2dsh/cron/v3"
"github.com/prometheus/client_golang/prometheus"
"github.com/robfig/cron/v3"

"github.com/zrepl/zrepl/daemon/logging/trace"
"github.com/zrepl/zrepl/endpoint"
Expand Down Expand Up @@ -104,16 +104,17 @@ func Run(ctx context.Context, conf *config.Config) error {
log.Info("starting daemon")

// start regular jobs
done := jobs.wait(jobs.startJobsWithCron(ctx, confJobs, false))
jobs.startJobsWithCron(ctx, confJobs, false)

wait := jobs.wait()
select {
case <-done.Done():
case <-wait.Done():
log.Info("all jobs finished")
case <-ctx.Done():
log.WithError(ctx.Err()).Info("context finished")
}
log.Info("waiting for jobs to finish")
<-done.Done()
<-wait.Done()
log.Info("daemon exiting")
return nil
}
Expand All @@ -138,15 +139,14 @@ func newJobs(log logger.Logger) *jobs {
}
}

func (s *jobs) wait(ctx context.Context) context.Context {
ctx2, cancel := context.WithCancel(context.Background())
func (s *jobs) wait() context.Context {
ctx, cancel := context.WithCancel(context.Background())
go func() {
s.wg.Wait()
<-s.cron.Stop().Done()
<-ctx.Done()
cancel()
}()
return ctx2
return ctx
}

type Status struct {
Expand Down Expand Up @@ -210,17 +210,11 @@ func (s *jobs) reset(job string) error {

func (s *jobs) startJobsWithCron(ctx context.Context, confJobs []job.Job,
internal bool,
) context.Context {
cronCtx, cancel := context.WithCancel(context.Background())
go func() {
s.cron.Run()
cancel()
}()

) {
s.cron.Start()
for _, j := range confJobs {
s.start(ctx, j, internal)
}
return cronCtx
}

const (
Expand Down
2 changes: 1 addition & 1 deletion daemon/job/active.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"sync"
"time"

"github.com/dsh2dsh/cron/v3"
"github.com/prometheus/client_golang/prometheus"
"github.com/robfig/cron/v3"

"github.com/zrepl/zrepl/config"
"github.com/zrepl/zrepl/daemon/job/reset"
Expand Down
2 changes: 1 addition & 1 deletion daemon/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"fmt"
"time"

"github.com/dsh2dsh/cron/v3"
"github.com/prometheus/client_golang/prometheus"
"github.com/robfig/cron/v3"

"github.com/zrepl/zrepl/daemon/logging"
"github.com/zrepl/zrepl/endpoint"
Expand Down
2 changes: 1 addition & 1 deletion daemon/job/passive.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"time"

"github.com/dsh2dsh/cron/v3"
"github.com/prometheus/client_golang/prometheus"
"github.com/robfig/cron/v3"

"github.com/zrepl/zrepl/daemon/logging/trace"

Expand Down
2 changes: 1 addition & 1 deletion daemon/job/snapjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"sync"
"time"

"github.com/dsh2dsh/cron/v3"
"github.com/prometheus/client_golang/prometheus"
"github.com/robfig/cron/v3"

"github.com/zrepl/zrepl/daemon/logging/trace"
"github.com/zrepl/zrepl/util/bandwidthlimit"
Expand Down
2 changes: 1 addition & 1 deletion daemon/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"net"
"net/http"

"github.com/dsh2dsh/cron/v3"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/robfig/cron/v3"

"github.com/zrepl/zrepl/config"
"github.com/zrepl/zrepl/daemon/job"
Expand Down
2 changes: 1 addition & 1 deletion daemon/snapper/manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package snapper
import (
"context"

"github.com/robfig/cron/v3"
"github.com/dsh2dsh/cron/v3"
)

type manual struct{}
Expand Down
2 changes: 1 addition & 1 deletion daemon/snapper/periodic.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"sync"
"time"

"github.com/robfig/cron/v3"
"github.com/dsh2dsh/cron/v3"

"github.com/zrepl/zrepl/config"
"github.com/zrepl/zrepl/daemon/hooks"
Expand Down
3 changes: 2 additions & 1 deletion daemon/snapper/snapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"fmt"
"time"

"github.com/robfig/cron/v3"
"github.com/dsh2dsh/cron/v3"

"github.com/zrepl/zrepl/config"
"github.com/zrepl/zrepl/zfs"
)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.22

require (
github.com/bits-and-blooms/bitset v1.13.0
github.com/dsh2dsh/cron/v3 v3.0.2
github.com/dsh2dsh/go-monitoringplugin/v2 v2.0.1
github.com/fatih/color v1.16.0
github.com/gdamore/tcell/v2 v2.7.4
Expand All @@ -19,7 +20,6 @@ require (
github.com/pkg/profile v1.7.0
github.com/problame/go-netssh v0.0.0-20201229122201-330ad6c9cc6f
github.com/prometheus/client_golang v1.19.0
github.com/robfig/cron/v3 v3.0.1
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dsh2dsh/cron/v3 v3.0.2 h1:3qfdkuD4SMYl2LgVOUC9R/mBTGyLHkJydXOseBAro2E=
github.com/dsh2dsh/cron/v3 v3.0.2/go.mod h1:FtMbaPkEs9y5oV1gjKtuHJ8MkRmyhtHn0+fmmuqHXzo=
github.com/dsh2dsh/go-monitoringplugin/v2 v2.0.1 h1:Gka5u1B8mWATcY++NhP9rHHACPe2pn1Ec0l3QFlj/TI=
github.com/dsh2dsh/go-monitoringplugin/v2 v2.0.1/go.mod h1:51/FMs9mcb6g0KUxrKQUidz6yLDdv4N5jpKirfswpYo=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
Expand Down Expand Up @@ -103,8 +105,6 @@ github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
Expand Down

0 comments on commit 63b4fe1

Please sign in to comment.