-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
111 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
Copyright 2021 Adevinta | ||
*/ | ||
|
||
package queue | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/go-kit/log" | ||
"github.com/go-kit/log/level" | ||
"github.com/hibiken/asynq" | ||
) | ||
|
||
type RedisConfig struct { | ||
Host string | ||
Port int | ||
Usr string | ||
Pwd string | ||
DB int | ||
} | ||
|
||
type RedisProducer struct { | ||
client *asynq.Client | ||
log log.Logger | ||
} | ||
|
||
// NewSQSProducer creates a new SQSProducer that allows to send messages to | ||
// the given queueARN. | ||
func NewRedisProducer(config RedisConfig, log log.Logger) *RedisProducer { | ||
if config.Host == "" { | ||
return nil | ||
} | ||
return &RedisProducer{ | ||
client: asynq.NewClient(&asynq.RedisClientOpt{ | ||
Addr: fmt.Sprintf("%s:%d", config.Host, config.Port), | ||
DB: config.DB, | ||
Username: config.Usr, | ||
Password: config.Pwd}), | ||
log: log, | ||
} | ||
} | ||
|
||
// SendMessage sends a message to the producer defined queue. | ||
func (s *RedisProducer) SendMessage(queueName string, body []byte) error { | ||
task := asynq.NewTask("checks", body) | ||
m, err := s.client.Enqueue(task, asynq.Queue(queueName), asynq.Timeout(10*time.Hour), asynq.MaxRetry(3)) | ||
level.Debug(s.log).Log("asynqId", m.ID, "queue", m.Queue) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters