Skip to content

Commit

Permalink
replace "golang.org/x/exp" with standard libraries (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
apocelipes authored Jan 31, 2025
1 parent d736ca2 commit 0c4a1a3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 23 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/robfig/cron/v3 v3.0.1
github.com/stretchr/testify v1.10.0
go.uber.org/goleak v1.3.0
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa
)

require (
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDTwym6AYBu0qzT8AcHdI=
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
4 changes: 1 addition & 3 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"errors"
"fmt"
"math/rand"
"slices"
"strings"
"time"

"github.com/google/uuid"
"github.com/jonboulle/clockwork"
"github.com/robfig/cron/v3"
"golang.org/x/exp/slices"
)

// internalJob stores the information needed by the scheduler
Expand Down Expand Up @@ -369,11 +369,9 @@ func (m monthlyJobDefinition) setup(j *internalJob, location *time.Location, _ t
}
}
daysStart = removeSliceDuplicatesInt(daysStart)
slices.Sort(daysStart)
ms.days = daysStart

daysEnd = removeSliceDuplicatesInt(daysEnd)
slices.Sort(daysEnd)
ms.daysFromEnd = daysEnd

atTimesDate, err := convertAtTimesToDateTime(m.atTimes, location)
Expand Down
12 changes: 3 additions & 9 deletions scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"context"
"reflect"
"runtime"
"slices"
"strings"
"time"

"github.com/google/uuid"
"github.com/jonboulle/clockwork"
"golang.org/x/exp/slices"
)

var _ Scheduler = (*scheduler)(nil)
Expand Down Expand Up @@ -267,14 +268,7 @@ func (s *scheduler) selectAllJobsOutRequest(out allJobsOutRequest) {
}
slices.SortFunc(outJobs, func(a, b Job) int {
aID, bID := a.ID().String(), b.ID().String()
switch {
case aID < bID:
return -1
case aID > bID:
return 1
default:
return 0
}
return strings.Compare(aID, bID)
})
select {
case <-s.shutdownCtx.Done():
Expand Down
11 changes: 3 additions & 8 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package gocron
import (
"context"
"reflect"
"slices"
"sync"
"time"

"github.com/google/uuid"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)

func callJobFuncWithParams(jobFunc any, params ...any) error {
Expand Down Expand Up @@ -63,12 +62,8 @@ func requestJobCtx(ctx context.Context, id uuid.UUID, ch chan jobOutRequest) *in
}

func removeSliceDuplicatesInt(in []int) []int {
m := make(map[int]struct{})

for _, i := range in {
m[i] = struct{}{}
}
return maps.Keys(m)
slices.Sort(in)
return slices.Compact(in)
}

func convertAtTimesToDateTime(atTimes AtTimes, location *time.Location) ([]time.Time, error) {
Expand Down

0 comments on commit 0c4a1a3

Please sign in to comment.