Skip to content

Commit

Permalink
Move to math/rand/v2 and away from internal service rand
Browse files Browse the repository at this point in the history
Follows up [1] to move to `math/rand/v2`, which automatically seeds
itself, and away from the internal random source that came in with
`baseservice.Archetype`.

[1] riverqueue/river#691
  • Loading branch information
brandur committed Dec 16, 2024
1 parent 31037a5 commit 1fa1d18
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add support for basic auth to the riverui executable. Thanks [Taras Turchenko](https://github.com/TArch64)! [PR #241](https://github.com/riverqueue/riverui/pull/241).

### Fixed

- Updated internal dependency of `riverqueue/river` to compensate for a change to `baseservice.Archetype` and a utility function. [PR #253](https://github.com/riverqueue/riverui/pull/253).

## [0.6.0] - 2024-11-26

### Added
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ require (
github.com/google/uuid v1.6.0
github.com/jackc/pgerrcode v0.0.0-20240316143900-6e2875d9b438
github.com/jackc/pgx/v5 v5.7.1
github.com/riverqueue/river v0.14.2
github.com/riverqueue/river/riverdriver v0.14.2
github.com/riverqueue/river/riverdriver/riverpgxv5 v0.14.2
github.com/riverqueue/river/rivershared v0.14.2
github.com/riverqueue/river/rivertype v0.14.2
github.com/riverqueue/river v0.14.3
github.com/riverqueue/river/riverdriver v0.14.3
github.com/riverqueue/river/riverdriver/riverpgxv5 v0.14.3
github.com/riverqueue/river/rivershared v0.14.3
github.com/riverqueue/river/rivertype v0.14.3
github.com/rs/cors v1.11.1
github.com/samber/slog-http v1.4.4
github.com/stretchr/testify v1.10.0
Expand Down
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,27 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/riverqueue/river v0.14.2 h1:I2VJ5HawamDDiL7QIy1XF2/PtwC+Re2y0OBR9Si6v/s=
github.com/riverqueue/river v0.14.2/go.mod h1:RHcZSKQuaYfylhbkIHcw+xUdBia3LtPJr66qsFCMj3Q=
github.com/riverqueue/river v0.14.3 h1:TkrGV40M7bYnEdfPviNmd4ide4Tn4n7ql3YUHclfO8c=
github.com/riverqueue/river v0.14.3/go.mod h1:RktlGq99TfIcByhZfecO7wHV6tPHmx8pqEGBEAWtN5o=
github.com/riverqueue/river/riverdriver v0.14.2 h1:7WSg3m8gjMbmwMeavBklkABLqy/+ox+Zg7d96zT0yBc=
github.com/riverqueue/river/riverdriver v0.14.2/go.mod h1:Z3mKValBmOfJGfOxd7FWeAQDR9tFkpYObqNS0BSJtMU=
github.com/riverqueue/river/riverdriver v0.14.3 h1:1cB5oR9p9YNXwnjXKLaB4OOyLHXS1zY03IaT0b0nsV0=
github.com/riverqueue/river/riverdriver v0.14.3/go.mod h1:uMpL544T3/0lWsvm9fSehvAw+E9AVOaJlZGgWxJEa7U=
github.com/riverqueue/river/riverdriver/riverdatabasesql v0.14.2 h1:SRUAmpZBIwJj8P8l6DK86z1jp7o31YSg4aresvnC8yc=
github.com/riverqueue/river/riverdriver/riverdatabasesql v0.14.2/go.mod h1:ThZfeDtiphBt3a0iwFQTy7uVTQ1DliC9cXdwNaPDQ2w=
github.com/riverqueue/river/riverdriver/riverdatabasesql v0.14.3 h1:ArFg/2WfvUnb8U3AgpW3jWCoc7V2Gqj4l6HNRP1/vtw=
github.com/riverqueue/river/riverdriver/riverpgxv5 v0.14.2 h1:+zhN3LGdzEoi/EmmNxMkunmeFd84XAB8ykDD8Rfqoq8=
github.com/riverqueue/river/riverdriver/riverpgxv5 v0.14.2/go.mod h1:OrpOHxAy4wOHGK2bwFKyOgKG353e2Z2EaPwO6RWlZp4=
github.com/riverqueue/river/riverdriver/riverpgxv5 v0.14.3 h1:WyT3+ToZbMvlfZqFVfX9L+EZB6e88/+L7PGhUqscPSU=
github.com/riverqueue/river/riverdriver/riverpgxv5 v0.14.3/go.mod h1:jvfJsqQPAWPifx8QuYnhhou/qV6DDE88ZooqbE5uiUE=
github.com/riverqueue/river/rivershared v0.14.2 h1:5cUC3jXYi1zLg7tPjsOwDPj9KQuxM1Mf5QBRS6QFHkc=
github.com/riverqueue/river/rivershared v0.14.2/go.mod h1:WZnOZV9KQgittVA01UH3/GI9RSgG0JfDkA/cohqV7v0=
github.com/riverqueue/river/rivershared v0.14.3 h1:dthcCxuL25EELDNvSJJl0Xl5GxMSxFPcQyc1I40BEH0=
github.com/riverqueue/river/rivershared v0.14.3/go.mod h1:wANyk6uuq0zi+6MYqj9NERQjws7w8rgqaUgsLqsG/sY=
github.com/riverqueue/river/rivertype v0.14.2 h1:otCEcibq2y5+HAxqvVPpc4tgShwISbFWrtqyL8qnI0M=
github.com/riverqueue/river/rivertype v0.14.2/go.mod h1:4vpt5ZSdZ35mFbRAV4oXgeRdH3Mq5h1pUzQTvaGfCUA=
github.com/riverqueue/river/rivertype v0.14.3 h1:kKYmgZ0w7YLCQoFTtr4iVyBP/+w8UeleCHQ2qWMrlvs=
github.com/riverqueue/river/rivertype v0.14.3/go.mod h1:4vpt5ZSdZ35mFbRAV4oXgeRdH3Mq5h1pUzQTvaGfCUA=
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.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
Expand Down
14 changes: 4 additions & 10 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/riverqueue/river"
"github.com/riverqueue/river/rivershared/baseservice"
"github.com/riverqueue/river/rivershared/startstop"
"github.com/riverqueue/river/rivershared/util/randutil"
"github.com/riverqueue/river/rivershared/util/valutil"

"riverqueue.com/riverui/internal/apiendpoint"
Expand Down Expand Up @@ -130,15 +129,10 @@ func NewServer(opts *ServerOpts) (*Server, error) {
serveIndex := serveIndexHTML(opts.DevMode, manifest, prefix, httpFS)

apiBundle := apiBundle{
// TODO: Switch to baseservice.NewArchetype when available.
archetype: &baseservice.Archetype{
Logger: opts.Logger,
Rand: randutil.NewCryptoSeededConcurrentSafeRand(),
Time: &baseservice.UnStubbableTimeGenerator{},
},
client: opts.Client,
dbPool: opts.DB,
logger: opts.Logger,
archetype: baseservice.NewArchetype(opts.Logger),
client: opts.Client,
dbPool: opts.DB,
logger: opts.Logger,
}

mux := http.NewServeMux()
Expand Down
3 changes: 2 additions & 1 deletion internal/querycacher/query_cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package querycacher

import (
"context"
"math/rand/v2"
"regexp"
"sync"
"time"
Expand Down Expand Up @@ -34,7 +35,7 @@ func NewQueryCacher[TRes any](archetype *baseservice.Archetype, db dbsqlc.DBTX,
// +/- 1s random variance to ticker interval. Makes sure that given multiple
// query caches running simultaneously, they all start and are scheduled a
// little differently to make a thundering herd problem less likely.
randomTickVariance := time.Duration(archetype.Rand.Float64()*float64(2*time.Second)) - 1*time.Second
randomTickVariance := time.Duration(rand.Float64()*float64(2*time.Second)) - 1*time.Second //nolint:gosec

queryCacher := baseservice.Init(archetype, &QueryCacher[TRes]{
db: db,
Expand Down

0 comments on commit 1fa1d18

Please sign in to comment.