Skip to content

Commit 4d374ba

Browse files
Refactor queue package: improve Redis address formatting and enhance video task creation
1 parent 98a5492 commit 4d374ba

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

internal/queue/server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package queue
22

33
import (
4+
"fmt"
5+
46
"github.com/Prateet-Github/worker-go/internal/config"
57
"github.com/hibiken/asynq"
68
)
79

810
func NewServer(cfg *config.Config) *asynq.Server {
911
return asynq.NewServer(
1012
asynq.RedisClientOpt{
11-
Addr: cfg.RedisHost + ":" + cfg.RedisPort,
13+
Addr: fmt.Sprintf("%s:%s", cfg.RedisHost, cfg.RedisPort),
1214
},
1315
asynq.Config{
1416
Concurrency: 5,

internal/queue/tasks.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
package queue
22

3-
const (
4-
TypeProcessVideo = "video:process"
3+
import (
4+
"encoding/json"
5+
6+
"github.com/hibiken/asynq"
57
)
68

9+
const TypeProcessVideo = "video:process"
10+
711
type VideoTask struct {
812
VideoID string `json:"videoId"`
913
S3Key string `json:"s3Key"`
1014
}
15+
16+
func NewProcessVideoTask(payload VideoTask) (*asynq.Task, error) {
17+
data, err := json.Marshal(payload)
18+
19+
if err != nil {
20+
return nil, err
21+
}
22+
23+
return asynq.NewTask(TypeProcessVideo, data), nil
24+
}

0 commit comments

Comments
 (0)