forked from tty47/torch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(torch): add queue to process the nodes when torch detects a even…
…t from k8s Signed-off-by: Jose Ramon Mañes <jose@celestia.org>
- Loading branch information
Showing
4 changed files
with
101 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package redis | ||
|
||
import ( | ||
"os" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
var ( | ||
redisHost = "" | ||
redisPort = "" | ||
redisPass = "" | ||
redisFullUrl = "" | ||
) | ||
|
||
// InitRedisConfig checks env vars and add default values in case we need | ||
func InitRedisConfig() *RedisClient { | ||
// redis config | ||
redisHost = GetRedisHost() | ||
redisPort = GetRedisPort() | ||
redisPass = GetRedisPass() | ||
redisFullUrl = GetRedisFullURL() | ||
|
||
log.Info("Redis host to connect: ", redisFullUrl) | ||
|
||
return NewRedisClient(redisFullUrl, redisPass, 0) | ||
} | ||
|
||
// GetRedisHost returns the redis host to connect | ||
func GetRedisHost() string { | ||
redisHost = os.Getenv("REDIS_HOST") | ||
if redisHost == "" { | ||
redisHost = "localhost" | ||
} | ||
return redisHost | ||
} | ||
|
||
// GetRedisPort returns the redis port | ||
func GetRedisPort() string { | ||
redisPort = os.Getenv("REDIS_PORT") | ||
if redisPort == "" { | ||
redisPort = "6379" | ||
} | ||
return redisPort | ||
} | ||
|
||
// GetRedisFullURL returns the full url | ||
func GetRedisFullURL() string { | ||
return redisHost + ":" + redisPort | ||
} | ||
|
||
// GetRedisPass returns the redis pass | ||
func GetRedisPass() string { | ||
redisPass = os.Getenv("REDIS_PASS") | ||
if redisPass == "" { | ||
redisPass = "" | ||
} | ||
return redisPass | ||
} |
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,38 @@ | ||
package redis | ||
|
||
import ( | ||
"github.com/adjust/rmq/v5" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// Producer add data into the queue. | ||
func Producer(data, queueName string) error { | ||
log.Info("Adding STS [", data, "] node to the queue: [", queueName, "]") | ||
data += "-0" | ||
log.Info("Getting the pod from the STS [", data, "]") | ||
|
||
connection, err := rmq.OpenConnection( | ||
"producer", | ||
"tcp", | ||
GetRedisFullURL(), | ||
2, | ||
nil, | ||
) | ||
if err != nil { | ||
log.Error("Error: ", err) | ||
return err | ||
} | ||
|
||
queue, err := connection.OpenQueue(queueName) | ||
if err != nil { | ||
log.Error("Error: ", err) | ||
return err | ||
} | ||
|
||
if err := queue.Publish(data); err != nil { | ||
log.Error("Error, failed to publish: ", err) | ||
return err | ||
} | ||
|
||
return nil | ||
} |
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