From 604175e6ca4136dd5345e6351e779187cad2843f Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Date: Tue, 4 Nov 2025 19:06:18 +0300 Subject: [PATCH] ci: format code with golangci-lint --- asynq_test.go | 2 +- doc.go | 81 ++++++++++++++------------- internal/errors/errors.go | 1 + servemux.go | 2 +- servemux_test.go | 2 +- subscriber.go | 2 +- tools/asynq/cmd/dash/screen_drawer.go | 11 ++-- tools/asynq/cmd/root.go | 24 ++++---- tools/asynq/cmd/task.go | 1 - 9 files changed, 66 insertions(+), 60 deletions(-) diff --git a/asynq_test.go b/asynq_test.go index 8d8af28..08afa82 100644 --- a/asynq_test.go +++ b/asynq_test.go @@ -11,11 +11,11 @@ import ( "strings" "testing" - "github.com/redis/go-redis/v9" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/hibiken/asynq/internal/log" h "github.com/hibiken/asynq/internal/testutil" + "github.com/redis/go-redis/v9" ) //============================================================================ diff --git a/doc.go b/doc.go index 76d1b4b..89f3df2 100644 --- a/doc.go +++ b/doc.go @@ -8,41 +8,41 @@ Package asynq provides a framework for Redis based distrubted task queue. Asynq uses Redis as a message broker. To connect to redis, specify the connection using one of RedisConnOpt types. - redisConnOpt = asynq.RedisClientOpt{ - Addr: "127.0.0.1:6379", - Password: "xxxxx", - DB: 2, - } + redisConnOpt = asynq.RedisClientOpt{ + Addr: "127.0.0.1:6379", + Password: "xxxxx", + DB: 2, + } The Client is used to enqueue a task. + client := asynq.NewClient(redisConnOpt) - client := asynq.NewClient(redisConnOpt) + // Task is created with two parameters: its type and payload. + // Payload data is simply an array of bytes. It can be encoded in JSON, Protocol Buffer, Gob, etc. + b, err := json.Marshal(ExamplePayload{UserID: 42}) + if err != nil { + log.Fatal(err) + } - // Task is created with two parameters: its type and payload. - // Payload data is simply an array of bytes. It can be encoded in JSON, Protocol Buffer, Gob, etc. - b, err := json.Marshal(ExamplePayload{UserID: 42}) - if err != nil { - log.Fatal(err) - } + task := asynq.NewTask("example", b) - task := asynq.NewTask("example", b) + // Enqueue the task to be processed immediately. + info, err := client.Enqueue(task) - // Enqueue the task to be processed immediately. - info, err := client.Enqueue(task) - - // Schedule the task to be processed after one minute. - info, err = client.Enqueue(t, asynq.ProcessIn(1*time.Minute)) + // Schedule the task to be processed after one minute. + info, err = client.Enqueue(t, asynq.ProcessIn(1*time.Minute)) The Server is used to run the task processing workers with a given handler. - srv := asynq.NewServer(redisConnOpt, asynq.Config{ - Concurrency: 10, - }) - if err := srv.Run(handler); err != nil { - log.Fatal(err) - } + srv := asynq.NewServer(redisConnOpt, asynq.Config{ + Concurrency: 10, + }) + + if err := srv.Run(handler); err != nil { + log.Fatal(err) + } Handler is an interface type with a method which takes a task and returns an error. Handler should return nil if @@ -50,23 +50,24 @@ the processing is successful, otherwise return a non-nil error. If handler panics or returns a non-nil error, the task will be retried in the future. Example of a type that implements the Handler interface. - type TaskHandler struct { - // ... - } - func (h *TaskHandler) ProcessTask(ctx context.Context, task *asynq.Task) error { - switch task.Type { - case "example": - var data ExamplePayload - if err := json.Unmarshal(task.Payload(), &data); err != nil { - return err - } - // perform task with the data + type TaskHandler struct { + // ... + } - default: - return fmt.Errorf("unexpected task type %q", task.Type) - } - return nil - } + func (h *TaskHandler) ProcessTask(ctx context.Context, task *asynq.Task) error { + switch task.Type { + case "example": + var data ExamplePayload + if err := json.Unmarshal(task.Payload(), &data); err != nil { + return err + } + // perform task with the data + + default: + return fmt.Errorf("unexpected task type %q", task.Type) + } + return nil + } */ package asynq diff --git a/internal/errors/errors.go b/internal/errors/errors.go index db0b92a..6437267 100644 --- a/internal/errors/errors.go +++ b/internal/errors/errors.go @@ -107,6 +107,7 @@ type Op string // only the last one is recorded. // // The types are: +// // errors.Op // The operation being performed, usually the method // being invoked (Get, Put, etc.). diff --git a/servemux.go b/servemux.go index 26bbf44..7f1517b 100644 --- a/servemux.go +++ b/servemux.go @@ -156,5 +156,5 @@ func NotFound(ctx context.Context, task *Task) error { return fmt.Errorf("%w %q", ErrHandlerNotFound, task.Type()) } -// NotFoundHandler returns a simple task handler that returns a ``not found`` error. +// NotFoundHandler returns a simple task handler that returns a “not found“ error. func NotFoundHandler() Handler { return HandlerFunc(NotFound) } diff --git a/servemux_test.go b/servemux_test.go index 227c4d7..267d14b 100644 --- a/servemux_test.go +++ b/servemux_test.go @@ -24,7 +24,7 @@ func makeFakeHandler(identity string) Handler { } // makeFakeMiddleware returns a middleware function that appends the given identity -//to the global invoked slice. +// to the global invoked slice. func makeFakeMiddleware(identity string) MiddlewareFunc { return func(next Handler) Handler { return HandlerFunc(func(ctx context.Context, t *Task) error { diff --git a/subscriber.go b/subscriber.go index 8fc4eac..7d5631f 100644 --- a/subscriber.go +++ b/subscriber.go @@ -8,9 +8,9 @@ import ( "sync" "time" - "github.com/redis/go-redis/v9" "github.com/hibiken/asynq/internal/base" "github.com/hibiken/asynq/internal/log" + "github.com/redis/go-redis/v9" ) type subscriber struct { diff --git a/tools/asynq/cmd/dash/screen_drawer.go b/tools/asynq/cmd/dash/screen_drawer.go index 3c07813..c8f0733 100644 --- a/tools/asynq/cmd/dash/screen_drawer.go +++ b/tools/asynq/cmd/dash/screen_drawer.go @@ -16,11 +16,12 @@ import ( // ScreenDrawer is used to draw contents on screen. // // Usage example: -// d := NewScreenDrawer(s) -// d.Println("Hello world", mystyle) -// d.NL() // adds newline -// d.Print("foo", mystyle.Bold(true)) -// d.Print("bar", mystyle.Italic(true)) +// +// d := NewScreenDrawer(s) +// d.Println("Hello world", mystyle) +// d.NL() // adds newline +// d.Print("foo", mystyle.Bold(true)) +// d.Print("bar", mystyle.Italic(true)) type ScreenDrawer struct { l *LineDrawer } diff --git a/tools/asynq/cmd/root.go b/tools/asynq/cmd/root.go index 9c1eb53..6e930f5 100644 --- a/tools/asynq/cmd/root.go +++ b/tools/asynq/cmd/root.go @@ -414,18 +414,22 @@ func getTLSConfig() *tls.Config { // cols is a list of headers and printRow specifies how to print rows. // // Example: -// type User struct { -// Name string -// Addr string -// Age int -// } +// +// type User struct { +// Name string +// Addr string +// Age int +// } +// // data := []*User{{"user1", "addr1", 24}, {"user2", "addr2", 42}, ...} // cols := []string{"Name", "Addr", "Age"} -// printRows := func(w io.Writer, tmpl string) { -// for _, u := range data { -// fmt.Fprintf(w, tmpl, u.Name, u.Addr, u.Age) -// } -// } +// +// printRows := func(w io.Writer, tmpl string) { +// for _, u := range data { +// fmt.Fprintf(w, tmpl, u.Name, u.Addr, u.Age) +// } +// } +// // printTable(cols, printRows) func printTable(cols []string, printRows func(w io.Writer, tmpl string)) { format := strings.Repeat("%v\t", len(cols)) + "\n" diff --git a/tools/asynq/cmd/task.go b/tools/asynq/cmd/task.go index e9ea792..d4799c3 100644 --- a/tools/asynq/cmd/task.go +++ b/tools/asynq/cmd/task.go @@ -770,4 +770,3 @@ func taskRunAll(cmd *cobra.Command, args []string) { } fmt.Printf("%d tasks are now pending\n", n) } -