Skip to content

Commit a2cb27f

Browse files
committed
refactor(docs): optimize comments following Google Go style guide
Simplified documentation comments to be more concise while maintaining clarity. Changed verbose phrases like "wraps detailed information" to simpler forms like "contains information". Removed redundant references to "Asynq" in internal documentation where context is clear. Applied consistent comment style across all exported types and functions.
1 parent a31b26a commit a2cb27f

6 files changed

Lines changed: 22 additions & 23 deletions

File tree

client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/hibiken/asynq"
99
)
1010

11-
// Client encapsulates an Asynq client instance with custom error handling and job retention settings.
11+
// Client encapsulates an asynq.Client instance with custom error handling and job retention settings.
1212
type Client struct {
1313
asynqClient *asynq.Client
1414
errorHandler ClientErrorHandler
@@ -88,7 +88,7 @@ func (c *Client) Enqueue(jobType string, payload any, opts ...JobOption) (string
8888
return c.EnqueueJob(job)
8989
}
9090

91-
// EnqueueJob adds a job to the queue based on the provided Job instance.
91+
// EnqueueJob adds a job to the queue.
9292
func (c *Client) EnqueueJob(job *Job) (string, error) {
9393
task, opts, err := job.ConvertToAsynqTask()
9494
if err != nil {
@@ -129,7 +129,7 @@ func (c *Client) handleJobError(err error, job *Job, msg string) {
129129
}
130130
}
131131

132-
// Stop terminates the Asynq client connection, releasing resources.
132+
// Stop terminates the client connection, releasing resources.
133133
func (c *Client) Stop() error {
134134
return c.asynqClient.Close()
135135
}

errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ var (
111111
ErrQueueNotEmpty = errors.New("queue is not empty")
112112
)
113113

114-
// ErrSkipRetry indicates a specific Asynq framework condition to skip retries and move the job to the archive.
114+
// ErrSkipRetry indicates a condition to skip retries and move the job to the archive.
115115
var ErrSkipRetry = asynq.SkipRetry
116116

117117
// NewSkipRetryError creates and wraps a SkipRetry error with a custom message.

info.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/hibiken/asynq"
77
)
88

9-
// WorkerInfo wraps detailed information about an Asynq server, which we treat as a "worker."
9+
// WorkerInfo contains detailed information about a worker server.
1010
type WorkerInfo struct {
1111
ID string `json:"id"`
1212
Host string `json:"host"`
@@ -19,7 +19,7 @@ type WorkerInfo struct {
1919
ActiveJobs []*ActiveJobInfo `json:"active_jobs"`
2020
}
2121

22-
// Convert Asynq ServerInfo to WorkerInfo.
22+
// toWorkerInfo converts asynq.ServerInfo to WorkerInfo.
2323
func toWorkerInfo(info *asynq.ServerInfo) *WorkerInfo {
2424
if info == nil {
2525
return nil
@@ -37,7 +37,7 @@ func toWorkerInfo(info *asynq.ServerInfo) *WorkerInfo {
3737
}
3838
}
3939

40-
// ActiveJobInfo wraps detailed information about a job currently being processed by a worker.
40+
// ActiveJobInfo contains information about a job currently being processed.
4141
type ActiveJobInfo struct {
4242
JobID string `json:"job_id"`
4343
JobType string `json:"job_type"`
@@ -47,7 +47,7 @@ type ActiveJobInfo struct {
4747
DeadlineAt time.Time `json:"deadline_at"`
4848
}
4949

50-
// Convert Asynq WorkerInfo to ActiveJobInfo.
50+
// toActiveJobInfo converts asynq.WorkerInfo to ActiveJobInfo.
5151
func toActiveJobInfo(info *asynq.WorkerInfo) *ActiveJobInfo {
5252
if info == nil {
5353
return nil
@@ -62,7 +62,7 @@ func toActiveJobInfo(info *asynq.WorkerInfo) *ActiveJobInfo {
6262
}
6363
}
6464

65-
// Convert a slice of Asynq WorkerInfo to a slice of ActiveJobInfo.
65+
// toActiveJobInfoList converts a slice of asynq.WorkerInfo to ActiveJobInfo.
6666
func toActiveJobInfoList(infos []*asynq.WorkerInfo) []*ActiveJobInfo {
6767
activeJobs := make([]*ActiveJobInfo, 0, len(infos))
6868
for _, info := range infos {
@@ -71,7 +71,7 @@ func toActiveJobInfoList(infos []*asynq.WorkerInfo) []*ActiveJobInfo {
7171
return activeJobs
7272
}
7373

74-
// QueueInfo includes detailed queue information.
74+
// QueueInfo contains detailed queue information.
7575
type QueueInfo struct {
7676
Queue string `json:"queue"`
7777
MemoryUsage int64 `json:"memory_usage"`
@@ -92,7 +92,7 @@ type QueueInfo struct {
9292
Timestamp time.Time `json:"timestamp"`
9393
}
9494

95-
// Convert Asynq QueueInfo to QueueInfo.
95+
// toQueueInfo converts asynq.QueueInfo to QueueInfo.
9696
func toQueueInfo(info *asynq.QueueInfo) *QueueInfo {
9797
if info == nil {
9898
return nil
@@ -118,7 +118,7 @@ func toQueueInfo(info *asynq.QueueInfo) *QueueInfo {
118118
}
119119
}
120120

121-
// QueueDailyStats includes detailed daily statistics for a queue.
121+
// QueueDailyStats contains daily statistics for a queue.
122122
type QueueDailyStats struct {
123123
Queue string `json:"queue"`
124124
Processed int `json:"processed"`
@@ -127,7 +127,7 @@ type QueueDailyStats struct {
127127
Date time.Time `json:"date"`
128128
}
129129

130-
// Convert Asynq QueueDailyStats to our QueueDailyStats structure.
130+
// toQueueDailyStats converts asynq.DailyStats to QueueDailyStats.
131131
func toQueueDailyStats(s *asynq.DailyStats) *QueueDailyStats {
132132
if s == nil {
133133
return nil
@@ -141,7 +141,7 @@ func toQueueDailyStats(s *asynq.DailyStats) *QueueDailyStats {
141141
}
142142
}
143143

144-
// JobInfo includes detailed information for a job, mirroring relevant parts of asynq's TaskInfo and WorkerInfo for active jobs.
144+
// JobInfo contains detailed information for a job.
145145
type JobInfo struct {
146146
ID string `json:"id"`
147147
Type string `json:"type"`
@@ -164,8 +164,7 @@ type JobInfo struct {
164164
Result *string `json:"result,omitempty"`
165165
}
166166

167-
// toJobInfo converts asynq.TaskInfo and optional asynq.WorkerInfo (for active tasks) to a JobInfo.
168-
// WorkerInfo is nil for non-active tasks.
167+
// toJobInfo converts asynq.TaskInfo and optional asynq.WorkerInfo to JobInfo.
169168
func toJobInfo(ti *asynq.TaskInfo, wi *asynq.WorkerInfo) *JobInfo {
170169
if ti == nil {
171170
return nil

job.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func WithDeadline(deadline *time.Time) JobOption {
8787
return func(j *Job) { j.Options.Deadline = deadline }
8888
}
8989

90-
// ConvertToAsynqTask converts the Job into an Asynq task, ready for enqueueing.
90+
// ConvertToAsynqTask converts the Job into an asynq.Task, ready for enqueueing.
9191
func (j *Job) ConvertToAsynqTask() (*asynq.Task, []asynq.Option, error) {
9292
if j.Type == "" {
9393
return nil, nil, ErrNoJobTypeSpecified
@@ -107,7 +107,7 @@ func (j *Job) ConvertToAsynqTask() (*asynq.Task, []asynq.Option, error) {
107107
return asynq.NewTask(j.Type, payloadBytes), opts, nil
108108
}
109109

110-
// ConvertToAsynqOptions converts the Job's options into Asynq options.
110+
// ConvertToAsynqOptions converts the Job's options into asynq.Option slice.
111111
func (j *Job) ConvertToAsynqOptions() []asynq.Option {
112112
opts := make([]asynq.Option, 0, 6)
113113

scheduler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
// ErrInvalidCronSpec is returned when a cron specification string cannot be parsed.
1313
var ErrInvalidCronSpec = errors.New("invalid cron spec")
1414

15-
// Scheduler manages job scheduling with Asynq.
15+
// Scheduler manages periodic job scheduling.
1616
type Scheduler struct {
1717
taskManager *asynq.PeriodicTaskManager
1818
configProvider ConfigProvider

worker.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const (
2828
// DefaultQueues defines default queue names and their priorities.
2929
var DefaultQueues = map[string]int{DefaultQueue: 1}
3030

31-
// Worker represents a worker that processes tasks using the asynq package.
31+
// Worker processes tasks from queues.
3232
type Worker struct {
3333
asynqServer *asynq.Server
3434
inspector *asynq.Inspector
@@ -186,7 +186,7 @@ func (w *Worker) Stop() error {
186186
return nil
187187
}
188188

189-
// setupAsynqServer initializes the Asynq server and inspector based on the provided Redis configuration and worker configuration.
189+
// setupAsynqServer initializes the asynq server and inspector.
190190
func (w *Worker) setupAsynqServer(redisConfig *RedisConfig, config *WorkerConfig) {
191191
asynqRedisOpt := redisConfig.ToAsynqRedisOpt()
192192

@@ -211,7 +211,7 @@ func (w *Worker) setupHandlers(mux *asynq.ServeMux) {
211211
}
212212
}
213213

214-
// makeHandlerFunc creates a task handling function for the Asynq server, applying rate limiting and error handling.
214+
// makeHandlerFunc creates a task handling function, applying rate limiting and error handling.
215215
func (w *Worker) makeHandlerFunc(handler *Handler) func(ctx context.Context, task *asynq.Task) error {
216216
finalHandler := handler.Process
217217
for i := len(w.middlewares) - 1; i >= 0; i-- {
@@ -265,7 +265,7 @@ func (w *Worker) makeHandlerFunc(handler *Handler) func(ctx context.Context, tas
265265
}
266266
}
267267

268-
// retryDelayFunc determines the delay before retrying a task after failure, using custom logic or falling back to Asynq's default.
268+
// retryDelayFunc determines the delay before retrying a task after failure.
269269
func (w *Worker) retryDelayFunc(count int, err error, task *asynq.Task) time.Duration {
270270
if rateLimitErr, ok := errors.AsType[*ErrRateLimit](err); ok {
271271
return rateLimitErr.RetryAfter

0 commit comments

Comments
 (0)