Štefan Bartoš
Štefan Bartoš

Reputation: 571

Rails Spring configuration similar like in Zeus?

I have something like this in Zeus custom plan, where I run some rake tasks:

require 'zeus/rails'

class CustomPlan < Zeus::Rails
  def rots
    `bundle exec rots 1> log/rots.log &`
  end

  def stripe_mock
    `bundle exec stripe-mock-server 1> log/stripe-mock-server.log &`
  end
end

Zeus.plan = CustomPlan.new

And Zeus config:

{
    "command": "ruby -rubygems -r./custom_plan -eZeus.go",

    "plan": {
      "boot": {
        "default_bundle": {
        "development_environment": {
        "prerake": {"rake": []},
        "console": ["c"]
      },
      "test_environment": {
        "test_helper": {"test": ["rspec"]}
      }
    },
    "rots": {},
    "stripe_mock": {}
    }
  }
}

And I found this link: https://github.com/rails/spring#configuration, but I don't exactly understand how I can run and stop my custom rake tasks.

I try it something like this:

class CustomPlan
  def initialize
    `bundle exec rots 1> log/rots.log &`
    `bundle exec stripe-mock-server 1> log/stripe-mock-server.log &`
  end
end
CustomPlan.new

This works, but when I stop spring by spring stop, stripe-mock-server is not shutting down.

Is it some clever solution for running and stopping custom rake in spring?

Thanks

Upvotes: 0

Views: 194

Answers (1)

Štefan Bartoš
Štefan Bartoš

Reputation: 571

Best solution what I came up for this moment:

# config/spring.rb
Spring.after_fork do
  `killall -v -9 rots & bundle exec rots 1> log/rots.log &`
  `killall -v -9 stripe-mock-server & bundle exec stripe-mock-server 1> log/stripe-mock-server.log &`
end

For first I kill all rots and stripe-mock-server if exists and run it again. If you find a better solution, let me know to comment. Thanks.

Upvotes: 0

Related Questions