Skip to content

Commit

Permalink
Relay 0.13.0 changes (#21)
Browse files Browse the repository at this point in the history
Allow setting state on Job creation.
  • Loading branch information
Dean Karn authored Apr 24, 2023
1 parent 302720f commit ea79716
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
--health-timeout 5s
--health-retries 5
relay:
image: ghcr.io/rust-playground/relay-rs:0.11.0
image: ghcr.io/rust-playground/relay-rs:latest
ports:
- 8080:8080
env:
Expand Down Expand Up @@ -57,6 +57,6 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: latest
5 changes: 0 additions & 5 deletions _examples/consumer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"math/rand"
"sync"
"sync/atomic"
"time"
Expand All @@ -16,10 +15,6 @@ var (
processed uint64
)

func init() {
rand.Seed(time.Now().UnixNano())
}

type payload struct {
Key string `json:"key"`
}
Expand Down
1 change: 0 additions & 1 deletion _examples/producer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var (
)

func init() {
rand.Seed(time.Now().UnixNano())
http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost = 1024
http.DefaultTransport.(*http.Transport).MaxConnsPerHost = 1024
}
Expand Down
7 changes: 2 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,19 @@ type Job[P any, S any] struct {
Payload P `json:"payload"`

// State is the raw JSON payload that the job runner will receive.
//
// This state will be ignored when enqueueing a Job and can only be set via a Heartbeat
// request.
State *S `json:"state,omitempty"`

// RunAt can optionally schedule/set a Job to be run only at a specific time in the
// future. This option should mainly be used for one-time jobs and scheduled jobs that have
// the option of being self-perpetuated in combination with the reschedule endpoint.
// the option of being self-perpetuated in combination with the rescheduling endpoint.
RunAt *time.Time `json:"run_at,omitempty"`

// UpdatedAt indicates last time the Job was updated either through enqueue, reschedule or heartbeat.
// This value is for reporting purposes only and will be ignored when enqueuing and rescheduling Jobs.
UpdatedAt *time.Time `json:"updated_at"`
}

// Config contains all information to create a new REaly instance fo use.
// Config contains all information to create a new Relay instance fo use.
type Config struct {
// BasURL of the HTTP server
BaseURL string
Expand Down
21 changes: 9 additions & 12 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ import (
)

var (
baseURL = os.Getenv("RELAY_URL")
baseURL = os.Getenv("RELAY_URL")
randSource = rand.New(rand.NewSource(time.Now().UnixNano()))
)

func init() {
rand.Seed(time.Now().UnixNano())
}

func TestOneTimeJob(t *testing.T) {

assert := require.New(t)
Expand All @@ -31,8 +28,8 @@ func TestOneTimeJob(t *testing.T) {
assert.NoError(err)

now := time.Now().UTC().Truncate(time.Millisecond)
id := strconv.Itoa(rand.Int())
queue := strconv.Itoa(rand.Int())
id := strconv.Itoa(randSource.Int())
queue := strconv.Itoa(randSource.Int())
job := Job[any, any]{
ID: id,
Queue: queue,
Expand Down Expand Up @@ -89,8 +86,8 @@ func TestReschedule(t *testing.T) {
assert.NoError(err)

now := time.Now().UTC().Truncate(time.Millisecond)
id := strconv.Itoa(rand.Int())
queue := strconv.Itoa(rand.Int())
id := strconv.Itoa(randSource.Int())
queue := strconv.Itoa(randSource.Int())
job := Job[any, any]{
ID: id,
Queue: queue,
Expand Down Expand Up @@ -147,9 +144,9 @@ func TestEnqueueMultiple(t *testing.T) {
assert.NoError(err)

now := time.Now().UTC().Truncate(time.Millisecond)
id := strconv.Itoa(rand.Int())
id2 := strconv.Itoa(rand.Int())
queue := strconv.Itoa(rand.Int())
id := strconv.Itoa(randSource.Int())
id2 := strconv.Itoa(randSource.Int())
queue := strconv.Itoa(randSource.Int())
job1 := Job[any, any]{
ID: id,
Queue: queue,
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
POSTGRES_HOST_AUTH_METHOD: trust

relay:
image: ghcr.io/rust-playground/relay-rs:0.9.0
image: ghcr.io/rust-playground/relay-rs:latest
environment:
- DATABASE_URL=postgres://username:pass@postgres:5432/relay?sslmode=disable
- HTTP_PORT=8080
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ go 1.18

require (
github.com/go-playground/backoff-sys v1.1.1
github.com/go-playground/errors/v5 v5.2.3
github.com/go-playground/pkg/v5 v5.6.0
github.com/go-playground/errors/v5 v5.3.0
github.com/go-playground/pkg/v5 v5.16.0
github.com/stretchr/testify v1.8.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-playground/assert/v2 v2.2.0 // indirect
github.com/go-playground/form/v4 v4.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ 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/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/backoff-sys v1.1.1 h1:wlzbS+239Px9AK8EtdG27lUvbX7AssIxFLYrZAud5KA=
github.com/go-playground/backoff-sys v1.1.1/go.mod h1:v6FlV3rjJ/qeUH0MEpypQGrVaQfqW5FSv9D+nXI68bY=
github.com/go-playground/errors/v5 v5.2.3 h1:RPxaFHgJZjgk/OFkUcfytJgRQKRINLtueVxgOdnfPpg=
github.com/go-playground/errors/v5 v5.2.3/go.mod h1:DincxRGwraWmq39TZDqtnOtHGOJ+AbNbO0OmBzX6MLw=
github.com/go-playground/errors/v5 v5.3.0 h1:Okot0WmH9v4bLz7wHad/gu1XrmqIHW6r5P4ubLv7QhE=
github.com/go-playground/errors/v5 v5.3.0/go.mod h1:LcLhmzQ/RuEntAs9r38NSV+xtbHffhMx/1yuuEroc7M=
github.com/go-playground/form/v4 v4.2.0 h1:N1wh+Goz61e6w66vo8vJkQt+uwZSoLz50kZPJWR8eic=
github.com/go-playground/form/v4 v4.2.0/go.mod h1:q1a2BY+AQUUzhl6xA/6hBetay6dEIhMHjgvJiGo6K7U=
github.com/go-playground/pkg/v5 v5.6.0 h1:97YpRFzIcS5NFP2Uzxj8cPYz4zTuwweyXADYcA1KfUQ=
github.com/go-playground/pkg/v5 v5.6.0/go.mod h1:TvZ2nNtNh6VfoNteY9ApA2BXt1ZwJliFZ4hzPAwLS9Y=
github.com/go-playground/pkg/v5 v5.16.0 h1:A/GZ5kitZuKQOEG1zm5tD9UrQRGl69k+MSck6Vojel8=
github.com/go-playground/pkg/v5 v5.16.0/go.mod h1:eT8XZeFHnqZkfkpkbI8ayjfCw9GohV2/j8STbVmoR6s=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down

0 comments on commit ea79716

Please sign in to comment.