Skip to content

Commit

Permalink
Disable cron job if in slave mode
Browse files Browse the repository at this point in the history
  • Loading branch information
cheungpat committed Sep 2, 2016
1 parent 152fa3e commit 3210493
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ func main() {

preprocessorRegistry := router.PreprocessorRegistry{}

cronjob := cron.New()
var cronjob *cron.Cron
if !config.App.Slave {
cronjob = cron.New()
}
initContext := plugin.InitContext{
Router: r,
Mux: serveMux,
Expand Down Expand Up @@ -246,7 +249,6 @@ func main() {
}

// Bootstrap finished, starting services
cronjob.Start()
initPlugin(config, &initContext)

log.Printf("Listening on %v...", config.HTTP.Host)
Expand Down Expand Up @@ -392,6 +394,10 @@ func initSubscription(config skyconfig.Configuration, connOpener func() (skydb.C
func initPlugin(config skyconfig.Configuration, initContext *plugin.InitContext) {
log.Infof("Supported plugin transports: %s", strings.Join(plugin.SupportedTransports(), ", "))

if initContext.Scheduler != nil {
initContext.Scheduler.Start()
}

for _, pluginConfig := range config.Plugin {
initContext.AddPluginConfiguration(pluginConfig.Transport, pluginConfig.Path, pluginConfig.Args)
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/server/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,15 @@ func (p *Plugin) processRegistrationInfo(context *InitContext, regInfo registrat
log.WithFields(logrus.Fields{
"regInfo": regInfo,
"transport": p.transport,
}).Debugln("Got configuration from pligin, registering")
}).Debugln("Got configuration from plugin, registering")
p.initHandler(context.Mux, context.Preprocessors, regInfo.Handlers)
p.initLambda(context.Router, context.Preprocessors, regInfo.Lambdas)
p.initHook(context.HookRegistry, regInfo.Hooks)
p.initTimer(context.Scheduler, regInfo.Timers)
if context.Scheduler != nil {
p.initTimer(context.Scheduler, regInfo.Timers)
} else {
log.Info("Ignoring scheduled cron jobs because server is in slave mode.")
}
p.initProvider(context.ProviderRegistry, regInfo.Providers)
}

Expand Down

0 comments on commit 3210493

Please sign in to comment.