Compare commits
2 Commits
master
...
feature/su
Author | SHA1 | Date |
---|---|---|
Naoki Kosaka | da16b3da58 | |
Naoki Kosaka | 773f5e28ec |
|
@ -8,6 +8,10 @@ services:
|
|||
volumes:
|
||||
- "./redisdata:/data"
|
||||
|
||||
# rabbitmq:
|
||||
# restart: always
|
||||
# image: rabbitmq:alpine
|
||||
|
||||
worker:
|
||||
build: .
|
||||
image: yukimochi/activity-relay
|
||||
|
@ -20,6 +24,7 @@ services:
|
|||
- "./config.yml:/var/lib/relay/config.yml"
|
||||
depends_on:
|
||||
- redis
|
||||
# - rabbitmq
|
||||
|
||||
server:
|
||||
build: .
|
||||
|
@ -33,3 +38,4 @@ services:
|
|||
- "./config.yml:/var/lib/relay/config.yml"
|
||||
depends_on:
|
||||
- redis
|
||||
# - rabbitmq
|
||||
|
|
2
main.go
2
main.go
|
@ -123,7 +123,6 @@ func buildCommand() *cobra.Command {
|
|||
func initConfig(cmd *cobra.Command) {
|
||||
if verbose {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
fmt.Println("DEBUG VIEW")
|
||||
}
|
||||
|
||||
configPath := cmd.Flag("config").Value.String()
|
||||
|
@ -137,6 +136,7 @@ func initConfig(cmd *cobra.Command) {
|
|||
logrus.Warn("Config file not exist. Use environment variables.")
|
||||
|
||||
viper.BindEnv("ACTOR_PEM")
|
||||
viper.BindEnv("BROKER_URL")
|
||||
viper.BindEnv("REDIS_URL")
|
||||
viper.BindEnv("RELAY_BIND")
|
||||
viper.BindEnv("RELAY_DOMAIN")
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# ACTOR_PEM: FILL_WITH_EACH_TEST
|
||||
# BROKER_URL: FILL_WITH_EACH_TEST
|
||||
# REDIS_URL: FILL_WITH_EACH_TEST
|
||||
|
||||
RELAY_BIND: 0.0.0.0:8080
|
||||
|
|
|
@ -19,7 +19,8 @@ type RelayConfig struct {
|
|||
actorKey *rsa.PrivateKey
|
||||
domain *url.URL
|
||||
redisClient *redis.Client
|
||||
redisURL string
|
||||
brokerURL *url.URL
|
||||
redisURL *url.URL
|
||||
serverBind string
|
||||
serviceName string
|
||||
serviceSummary string
|
||||
|
@ -57,8 +58,11 @@ func NewRelayConfig() (*RelayConfig, error) {
|
|||
return nil, errors.New("ACTOR_PEM: " + err.Error())
|
||||
}
|
||||
|
||||
redisURL := viper.GetString("REDIS_URL")
|
||||
redisOption, err := redis.ParseURL(redisURL)
|
||||
redisURL, err := url.ParseRequestURI(viper.GetString("REDIS_URL"))
|
||||
if err != nil {
|
||||
return nil, errors.New("REDIS_URL: " + err.Error())
|
||||
}
|
||||
redisOption, err := redis.ParseURL(redisURL.String())
|
||||
if err != nil {
|
||||
return nil, errors.New("REDIS_URL: " + err.Error())
|
||||
}
|
||||
|
@ -68,12 +72,19 @@ func NewRelayConfig() (*RelayConfig, error) {
|
|||
return nil, errors.New("Redis Connection Test: " + err.Error())
|
||||
}
|
||||
|
||||
brokerURL, err := url.ParseRequestURI(viper.GetString("BROKER_URL"))
|
||||
if err != nil {
|
||||
logrus.Warn("BROKER_URL: INVALID OR EMPTY. USE REDIS_URL.")
|
||||
brokerURL = redisURL
|
||||
}
|
||||
|
||||
serverBind := viper.GetString("RELAY_BIND")
|
||||
|
||||
return &RelayConfig{
|
||||
actorKey: privateKey,
|
||||
domain: domain,
|
||||
redisClient: redisClient,
|
||||
brokerURL: brokerURL,
|
||||
redisURL: redisURL,
|
||||
serverBind: serverBind,
|
||||
serviceName: viper.GetString("RELAY_SERVICENAME"),
|
||||
|
@ -120,19 +131,25 @@ func (relayConfig *RelayConfig) DumpWelcomeMessage(moduleName string, version st
|
|||
- Configuration
|
||||
RELAY NAME : %s
|
||||
RELAY DOMAIN : %s
|
||||
BROKER URL : %s
|
||||
REDIS URL : %s
|
||||
BIND ADDRESS : %s
|
||||
JOB_CONCURRENCY : %s
|
||||
`, version, moduleName, relayConfig.serviceName, relayConfig.domain.Host, relayConfig.redisURL, relayConfig.serverBind, strconv.Itoa(relayConfig.jobConcurrency))
|
||||
`, version, moduleName, relayConfig.serviceName, relayConfig.domain.Host, relayConfig.brokerURL, relayConfig.redisURL, relayConfig.serverBind, strconv.Itoa(relayConfig.jobConcurrency))
|
||||
}
|
||||
|
||||
// NewMachineryServer create Redis backed Machinery Server from RelayConfig.
|
||||
func NewMachineryServer(globalConfig *RelayConfig) (*machinery.Server, error) {
|
||||
cnf := &config.Config{
|
||||
Broker: globalConfig.redisURL,
|
||||
Broker: globalConfig.brokerURL.String(),
|
||||
DefaultQueue: "relay",
|
||||
ResultBackend: globalConfig.redisURL,
|
||||
ResultBackend: globalConfig.redisURL.String(),
|
||||
ResultsExpireIn: 1,
|
||||
AMQP: &config.AMQPConfig{
|
||||
Exchange: "relay_exchange",
|
||||
ExchangeType: "direct",
|
||||
BindingKey: "relay_task",
|
||||
},
|
||||
}
|
||||
newServer, err := machinery.NewServer(cnf)
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ func TestRelayConfig_DumpWelcomeMessage(t *testing.T) {
|
|||
"module NAME": "Testing",
|
||||
"RELAY NANE": relayConfig.serviceName,
|
||||
"RELAY DOMAIN": relayConfig.domain.Host,
|
||||
"REDIS URL": relayConfig.redisURL,
|
||||
"REDIS URL": relayConfig.redisURL.String(),
|
||||
"BIND ADDRESS": relayConfig.serverBind,
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ relay --config /path/to/config.yml control
|
|||
|
||||
```yaml config.yml
|
||||
ACTOR_PEM: /var/lib/relay/actor.pem
|
||||
# BROKER_URL: amqp://guest:guest@rabbitmq:5672 # IF EMPTY, USE REDIS_URL
|
||||
REDIS_URL: redis://redis:6379
|
||||
|
||||
RELAY_BIND: 0.0.0.0:8080
|
||||
|
@ -63,6 +64,7 @@ JOB_CONCURRENCY: 50
|
|||
This is **Optional** : When `config.yml` not exists, use environment variable.
|
||||
|
||||
- ACTOR_PEM
|
||||
- BROKER_URL
|
||||
- REDIS_URL
|
||||
- RELAY_BIND
|
||||
- RELAY_DOMAIN
|
||||
|
|
Loading…
Reference in New Issue