Skip to content

Commit

Permalink
Disable pubsub and related features in slave mode
Browse files Browse the repository at this point in the history
Subscriptions and pubsub router will be run by skygear server in
leader mode. Cloudcode should connect to leader by configuring
the PUBSUB_URL environment variable.

refs SkygearIO#105
  • Loading branch information
cheungpat committed Sep 2, 2016
1 parent b6c3d65 commit a0be5a7
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ func main() {
Config: config,
}

internalHub := pubsub.NewHub()
initSubscription(config, connOpener, internalHub, pushSender)
initDevice(config, connOpener)
var internalHub *pubsub.Hub
if !config.App.Slave {
internalHub = pubsub.NewHub()
initSubscription(config, connOpener, internalHub, pushSender)
initDevice(config, connOpener)
}

// Preprocessor
preprocessorRegistry["notification"] = &pp.NotificationPreprocessor{
Expand Down Expand Up @@ -205,17 +208,19 @@ func main() {
serveMux.Handle("/", r)

// Following section is for Gateway
pubSub := pubsub.NewWsPubsub(nil)
pubSubGateway := router.NewGateway("", "/pubsub", serveMux)
pubSubGateway.GET(injector.InjectProcessors(&handler.PubSubHandler{
WebSocket: pubSub,
}))

internalPubSub := pubsub.NewWsPubsub(internalHub)
internalPubSubGateway := router.NewGateway("", "/_/pubsub", serveMux)
internalPubSubGateway.GET(injector.InjectProcessors(&handler.PubSubHandler{
WebSocket: internalPubSub,
}))
if !config.App.Slave {
pubSub := pubsub.NewWsPubsub(nil)
pubSubGateway := router.NewGateway("", "/pubsub", serveMux)
pubSubGateway.GET(injector.InjectProcessors(&handler.PubSubHandler{
WebSocket: pubSub,
}))

internalPubSub := pubsub.NewWsPubsub(internalHub)
internalPubSubGateway := router.NewGateway("", "/_/pubsub", serveMux)
internalPubSubGateway.GET(injector.InjectProcessors(&handler.PubSubHandler{
WebSocket: internalPubSub,
}))
}

fileGateway := router.NewGateway("files/(.+)", "/files/", serveMux)
fileGateway.GET(injector.Inject(&handler.AssetGetURLHandler{}))
Expand Down

0 comments on commit a0be5a7

Please sign in to comment.