In an normal release, Rails app's unit testing will avoid most errors. But for the urgent code publishing, we have got several time of typo error. Code syntax error may cause server crash for a little while(Passenger web server and we using ./tmp/restart.txt
to restart). We use Capistrano to publish code, so I plan to add a syntax checking before publishing code.
The method is writing a task to bundle exec rails runner, this will report most ruby syntax error(except the undef variables in some functions, runner will load .rb files).
then add this in the deploy.rb (Capistrano 3.1):
This is not a tricky part, but please pay attention to the line:
This line of code cost me some time, I forget the 2>&1
. so res
will just got the stdout, not the stderr output, which causes the exception is not raised, and Capistrano flow is not stopped.