Skip to content

Commit

Permalink
Upgrade to Go 1.21, remove math.Rand usage and fix a loop alias error
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed Sep 20, 2023
1 parent c4537e5 commit 67a0027
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 21 deletions.
13 changes: 6 additions & 7 deletions client/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package client
import (
cryptorand "crypto/rand"
"encoding/base64"
mathrand "math/rand"
"fmt"
"time"
)

Expand Down Expand Up @@ -65,8 +65,7 @@ func RandomJid() string {
bytes := make([]byte, 12)
_, err := cryptorand.Read(bytes)
if err != nil {
//nolint:gosec
mathrand.Read(bytes)
panic(fmt.Errorf("unable to read random bytes: %w", err))
}

return base64.RawURLEncoding.EncodeToString(bytes)
Expand Down Expand Up @@ -108,10 +107,10 @@ func (j *Job) SetUniqueFor(secs uint) *Job {
// Configure the uniqueness deadline for this job, legal values
// are:
//
// - "success" - the job will be considered unique until it has successfully processed
// or the +unique_for+ TTL has passed, this is the default value.
// - "start" - the job will be considered unique until it starts processing. Retries
// may lead to multiple copies of the job running.
// - "success" - the job will be considered unique until it has successfully processed
// or the +unique_for+ TTL has passed, this is the default value.
// - "start" - the job will be considered unique until it starts processing. Retries
// may lead to multiple copies of the job running.
func (j *Job) SetUniqueness(until UniqueUntil) *Job {
return j.SetCustom("unique_until", until)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/contribsys/faktory

go 1.19
go 1.21

require (
github.com/BurntSushi/toml v0.4.1
Expand Down
1 change: 1 addition & 0 deletions server/task_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (ts *taskRunner) cycle() {
ts.mutex.RLock()
defer ts.mutex.RUnlock()
for _, t := range ts.tasks {
t := t
if sec%t.every != 0 {
continue
}
Expand Down
10 changes: 0 additions & 10 deletions test/load/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ func main() {
threads = athreads
}

seed := int64(420)
if argc > 3 {
aseed, err := strconv.ParseInt(os.Args[3], 10, 64)
if err != nil {
log.Fatal(err)
}
seed = aseed
}

fmt.Printf("Running loadtest with %d jobs and %d threads\n", jobs, threads)

client, err := faktory.Open()
Expand All @@ -61,7 +52,6 @@ func main() {
defer client.Close()
client.Flush()

rand.Seed(int64(seed))
opsCount = make([]int, threads)
run()
}
Expand Down
4 changes: 1 addition & 3 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/base64"
"fmt"
"math/big"
mathrand "math/rand"
"os"
"runtime"
"time"
Expand Down Expand Up @@ -58,8 +57,7 @@ func RandomJid() string {
bytes := make([]byte, 12)
_, err := cryptorand.Read(bytes)
if err != nil {
//nolint:gosec
mathrand.Read(bytes)
panic(fmt.Errorf("unable to read random bytes: %w", err))
}

return base64.RawURLEncoding.EncodeToString(bytes)
Expand Down

0 comments on commit 67a0027

Please sign in to comment.