I’m trying to create a migration for my app, and in this app I’m using a gem that tries to startup a different service upon app startup. Apparently, creating a migration…
rails generate migration AddSomeStuffToTable stuff:string
…activates the app, and this gem which tries to connect to startup the service. It appears that starting up the app via generating a migration makes the service startup unable to connect, so it just keeps sleeping and trying again, never actually running the migration.
In this gem, I’ve already dealt with this for rake, so this is what I’ve got so far:
MyService.start unless defined? Rake or defined? IRB
This handles the rake problem (like rake db:migrate, rake db:populate), but how can I handle the creation of migration, which (as far as I know) is not a Rake task?
You could try using environment variables for disabling the service:
And run your command like this:
However, I doubt this scales well, especially if multiple developers are in the app. A better approach might be to do the reverse of this, to only start the service if a particular env variable is present. However, going this direction, you’d need to make sure your app servers set this variable, for example:
Apache:
SetEnv START_SERVICE 1nginx:
env START_SERVICE=1thin:
START_SERVICE=1 thin start