0

Our app - Rails 4.1, Passenger 4, deployed with Capistrano 3.1.

When processing credit card transactions I log it pending in our DB and then hit Authorize.net to actually charge $. On success I update transaction in our system.

I want to make sure that Passenger does not restart while it's waiting for Authorize.net to respond. One option is to query DB to see if there are pending transactions and wait to restart Passenger.

How can I load Rails Env and access the model from Capistrano task? It's quite easy from rake task. Something like this in deploy.rb:

task :restart do
  on roles(:app), in: :sequence, wait: 5 do
    If Donations.pending == true
        sleep 5
    else
      execute :touch, release_path.join('tmp/restart.txt')
    end
  end
end

I am open to other suggestions as well. I thank you in advance for any advice.

Dmitry Polyakovsky
  • 1,535
  • 11
  • 31

1 Answers1

0

I think your answer may actually be there in your question: use a rake task. Capistrano itself does not run on the server, and probably does not have access to the database used by the running system. But a rake task running on the app server should have access to the full application stack, enabling you to use your application's real models.

Have a look at How do I run a rake task from Capistrano?

Community
  • 1
  • 1
Josh Williams
  • 68
  • 1
  • 7