Skip to content

Commit

Permalink
Merge pull request #97 from ripienaar/dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: R.I.Pienaar <[email protected]>
  • Loading branch information
ripienaar authored Dec 18, 2022
2 parents 6dcd63a + 31a0f0f commit 075e84c
Show file tree
Hide file tree
Showing 29 changed files with 173 additions and 607 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
test:
strategy:
matrix:
go: [ 1.17, 1.18 ]
go: [ 1.18, 1.19 ]

runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ client, _ := asyncjobs.NewClient(
asyncjobs.RetryBackoffPolicy(asyncjobs.RetryLinearTenMinutes))

router := asyncjobs.NewTaskRouter()
router.Handler("email:new", func(ctx context.Context, log asyncjobs.Logger, task *asyncjobs.Task) (interface{}, error) {
router.Handler("email:new", func(ctx context.Context, log asyncjobs.Logger, task *asyncjobs.Task) (any, error) {
log.Printf("Processing task %s", task.ID)

// do work here using task.Payload
Expand Down
2 changes: 1 addition & 1 deletion ajc/task_cron_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (c *taskCronCommand) addAction(_ *fisk.ParseContext) error {
opts = append(opts, aj.TaskMaxTries(c.maxtries))
}

var payload interface{}
var payload any
if c.payload != "" {
payload = c.payload
}
Expand Down
2 changes: 1 addition & 1 deletion ajc/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func humanizeDuration(d time.Duration) string {
return fmt.Sprintf("%.2fs", d.Seconds())
}

func dumpJSON(d interface{}) {
func dumpJSON(d any) {
j, err := json.MarshalIndent(d, "", " ")
if err != nil {
panic(fmt.Sprintf("could not JSON render: %v", err))
Expand Down
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (c *Client) saveOrDiscardTaskIfDesired(ctx context.Context, t *Task) error
return c.storage.DeleteTaskByID(t.ID)
}

func (c *Client) setTaskSuccess(ctx context.Context, t *Task, payload interface{}) error {
func (c *Client) setTaskSuccess(ctx context.Context, t *Task, payload any) error {
t.LastTriedAt = nowPointer()
t.State = TaskStateCompleted
t.LastErr = ""
Expand Down
6 changes: 3 additions & 3 deletions client_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"time"
)

func newEmail(to, subject, body string) map[string]interface{} {
return map[string]interface{}{
func newEmail(to, subject, body string) map[string]any {
return map[string]any{
"to": to,
"subject": subject,
"body": body,
Expand Down Expand Up @@ -71,7 +71,7 @@ func ExampleClient_consumer() {
panicIfErr(err)

router := NewTaskRouter()
err = router.HandleFunc("email:send", func(_ context.Context, _ Logger, t *Task) (interface{}, error) {
err = router.HandleFunc("email:send", func(_ context.Context, _ Logger, t *Task) (any, error) {
log.Printf("Processing task: %s", t.ID)

// handle task.Payload which is a JSON encoded email
Expand Down
7 changes: 3 additions & 4 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"sync"
Expand All @@ -29,7 +28,7 @@ func TestAsyncJobs(t *testing.T) {
}

func withJetStream(cb func(nc *nats.Conn, mgr *jsm.Manager)) {
d, err := ioutil.TempDir("", "jstest")
d, err := os.MkdirTemp("", "jstest")
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(d)

Expand Down Expand Up @@ -152,7 +151,7 @@ var _ = Describe("Client", func() {
handled := int32(0)

router := NewTaskRouter()
router.HandleFunc("test", func(ctx context.Context, log Logger, t *Task) (interface{}, error) {
router.HandleFunc("test", func(ctx context.Context, log Logger, t *Task) (any, error) {
if t.Tries > 1 {
log.Infof("Try %d for task %s", t.Tries, t.ID)
}
Expand Down Expand Up @@ -212,7 +211,7 @@ var _ = Describe("Client", func() {
var tries []time.Time

router := NewTaskRouter()
router.HandleFunc("ginkgo", func(ctx context.Context, log Logger, t *Task) (interface{}, error) {
router.HandleFunc("ginkgo", func(ctx context.Context, log Logger, t *Task) (any, error) {
tries = append(tries, time.Now())

log.Infof("Trying task %s on try %d\n", t.ID, t.Tries)
Expand Down
2 changes: 1 addition & 1 deletion docs/content/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ client, _ := asyncjobs.NewClient(
asyncjobs.RetryBackoffPolicy(asyncjobs.RetryLinearTenMinutes))

router := asyncjobs.NewTaskRouter()
router.Handler("email:new", func(ctx context.Context, log asyncjobs.Logger, task *asyncjobs.Task) (interface{}, error) {
router.Handler("email:new", func(ctx context.Context, log asyncjobs.Logger, task *asyncjobs.Task) (any, error) {
log.Printf("Processing task %s", task.ID)

// do work here using task.Payload
Expand Down
4 changes: 2 additions & 2 deletions docs/content/overview/golang-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Any number of producers can create tasks from any number of different processes.
First we have a simplistic helper to create a map that describes an email:

```go
func newEmail(to, subject, body string) interface{} {
func newEmail(to, subject, body string) any {
return map[string]string{"to": to, "subject": subject, "body": body}
}
```
Expand Down Expand Up @@ -105,7 +105,7 @@ client, err := asyncjobs.NewClient(
panicIfErr(err)

router := asyncjobs.NewTaskRouter()
err = router.Handler("email:new", func(ctx context.Context, log asyncjobs.Logger, task *asyncjobs.Task) (interface{}, error) {
err = router.Handler("email:new", func(ctx context.Context, log asyncjobs.Logger, task *asyncjobs.Task) (any, error) {
log.Printf("Processing task %s", task.ID)

// do work here using task.Payload
Expand Down
2 changes: 1 addition & 1 deletion docs/content/overview/handlers-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
aj "github.com/choria-io/asyncjobs"
)

func AsyncJobHandler(ctx context.Context, log aj.Logger, task *aj.Task) (interface{}, error) {
func AsyncJobHandler(ctx context.Context, log aj.Logger, task *aj.Task) (any, error) {
// process your email
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/content/reference/routing-concurrency-retry.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Below is a handler that sends an email, the task Payload is a serialized object
The Task handler then is a single-purpose piece of code capable of handling 1 type of Task.

```go
func emailNewHandler(ctx context.Context, log asycjobs.Logger, task *asyncjobs.Task) (interface{}, error) {
func emailNewHandler(ctx context.Context, log asycjobs.Logger, task *asyncjobs.Task) (any, error) {
// Parse the task payload into an email
email, err := parseEmail(task.Payload)
if err != nil { return nil, err }
Expand Down
2 changes: 1 addition & 1 deletion docs/content/reference/terminology.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Connects to JetStream and manages the enqueueing and routing of tasks.

## Handler

Handlers are functions that can process a task with the signature `func(context.Context, *asyncjobs.Task) (interface{}, error)`.
Handlers are functions that can process a task with the signature `func(context.Context, *asyncjobs.Task) (any, error)`.

## Router

Expand Down
2 changes: 1 addition & 1 deletion election/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func NewElection(name string, key string, bucket nats.KeyValue, opts ...Option)
return e, nil
}

func (e *election) debugf(format string, a ...interface{}) {
func (e *election) debugf(format string, a ...any) {
if e.opts.debug == nil {
return
}
Expand Down
7 changes: 3 additions & 4 deletions election/election_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package election
import (
"context"
"fmt"
"io/ioutil"
"os"
"sync"
"testing"
Expand All @@ -31,7 +30,7 @@ var _ = Describe("Leader Election", func() {
js nats.KeyValueManager
kv nats.KeyValue
err error
debugger func(f string, a ...interface{})
debugger func(f string, a ...any)
)

BeforeEach(func() {
Expand All @@ -45,7 +44,7 @@ var _ = Describe("Leader Election", func() {
TTL: 750 * time.Millisecond,
})
Expect(err).ToNot(HaveOccurred())
debugger = func(f string, a ...interface{}) {
debugger = func(f string, a ...any) {
fmt.Fprintf(GinkgoWriter, fmt.Sprintf("%s\n", f), a...)
}
})
Expand Down Expand Up @@ -208,7 +207,7 @@ var _ = Describe("Leader Election", func() {
func startJSServer(t GinkgoTInterface) (*server.Server, *nats.Conn) {
t.Helper()

d, err := ioutil.TempDir("", "jstest")
d, err := os.MkdirTemp("", "jstest")
if err != nil {
t.Fatalf("temp dir could not be made: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions election/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type options struct {
lostCb func()
campaignCb func(s State)
bo Backoff
debug func(format string, a ...interface{})
debug func(format string, a ...any)
}

// WithBackoff will use the provided Backoff timer source to decrease campaign intervals over time
Expand All @@ -47,6 +47,6 @@ func OnCampaign(cb func(s State)) Option {
}

// WithDebug sets a function to do debug logging with
func WithDebug(cb func(format string, a ...interface{})) Option {
func WithDebug(cb func(format string, a ...any)) Option {
return func(o *options) { o.debug = cb }
}
2 changes: 1 addition & 1 deletion generators/godocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (g *GoContainer) RenderToDirectory(target string) error {
}
}

funcs := map[string]interface{}{
funcs := map[string]any{
"RetryNamesList": func() string {
return strings.Join(aj.RetryPolicyNames(), ", ")
},
Expand Down
59 changes: 32 additions & 27 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,47 +1,52 @@
module github.com/choria-io/asyncjobs

go 1.17
go 1.18

require (
github.com/AlecAivazis/survey/v2 v2.3.4
github.com/choria-io/fisk v0.0.3-0.20220605065054-0cf82636ff4e
github.com/AlecAivazis/survey/v2 v2.3.6
github.com/choria-io/fisk v0.2.1
github.com/dustin/go-humanize v1.0.0
github.com/nats-io/jsm.go v0.0.33
github.com/nats-io/nats-server/v2 v2.8.4
github.com/nats-io/nats.go v1.16.0
github.com/onsi/ginkgo/v2 v2.1.4
github.com/onsi/gomega v1.19.0
github.com/prometheus/client_golang v1.12.2
github.com/nats-io/jsm.go v0.0.35
github.com/nats-io/nats-server/v2 v2.9.9
github.com/nats-io/nats.go v1.21.0
github.com/onsi/ginkgo/v2 v2.6.1
github.com/onsi/gomega v1.24.2
github.com/prometheus/client_golang v1.14.0
github.com/robfig/cron/v3 v3.0.1
github.com/segmentio/ksuid v1.0.4
github.com/sirupsen/logrus v1.8.1
github.com/sirupsen/logrus v1.9.0
github.com/xlab/tablewriter v0.0.0-20160610135559-80b567a11ad5
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467
golang.org/x/term v0.3.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.15.5 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/klauspost/compress v1.15.13 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/nats-io/jwt/v2 v2.2.1-0.20220330180145-442af02fd36a // indirect
github.com/nats-io/jwt/v2 v2.3.0 // indirect
github.com/nats-io/nkeys v0.3.1-0.20220214171627-79ae42e4d898 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.39.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
golang.org/x/crypto v0.4.0 // indirect
golang.org/x/net v0.4.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.4.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
)
Loading

0 comments on commit 075e84c

Please sign in to comment.