How can you tell if running a command through the heroku cli succeeded? - heroku

When running a command through heroku, such as:
heroku run rake db:migrate
I would like to know if the command succeeded or not. Unfortunately, even if running the migration fails, I get an exit status of 0.
I'm writing some ruby code that wraps this command and invokes it, and raises an error if the command failed. The code looks like:
Open3.popen2e('heroku run rake db:migrate') do |stdin, stdout_and_stderr, wait_thr|
raise 'running migration failed' unless wait_thr.value.success?
end
Even when running this fails, and I get a message:
rake aborted! StandardError: An error has occurred, this and all later
migrations canceled:
My code itself does not raise an error. Inspecting wait_thr.value in the above code, it has an exit code of 0, which means the heroku CLI believes the rake call succeeded.
How can my code know if the command that was run by the heroku cli failed? Is there a way to tell the heroku CLI to return the status code of the command it ran?

There is now official support for this from their CLI:
heroku help run
Usage: heroku run COMMAND
run an attached dyno
-s, --size SIZE # specify dyno size
--exit-code # return exit code from process
So you would now run:
heroku run --exit-code rake db:migrate

You're not alone with this. Many have complained about this before, check this out:
https://github.com/heroku/heroku/issues/186
You can (dirty) work around the problem with this gem:
https://github.com/glenngillen/heroku-exit-status

Related

Ruby: 'Zip is not installed' error message when running on Win CMD this: buildpack-packager --uncached

I'm running cmd command buildpack-packer --uncached (or any other option of buildpack-packer). I had many error messages prior that. They were caused by bad content of manifest.yml. I corrected them. So now I receive this error message: Zip is not installed (RuntimeError)
I used gem install to install zip gem and rubyzip gem (as first did not work, so I tried a second). So now both not helping to get rid of this error message.
Here is a part of the installed gem list:
And here is the code that drops this error (found it based on the error message in file: C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/buildpack-packager-2.3.4/lib/buildpack/packager.rb):
I'm quite new in Ruby, so maybe I do some very basic mistake...
Thx in advance!!
Please don't use pictures or screenshots in your post. Use plaintext only.
I think you are misunderstanding the code:
_, _, status = Open3.capture3('which zip')
It checks if you have any zip program (executable) installed not a ruby gem (library). It actually executes which zip in your cmd shell.
For example on my system it found an oracle one:
c:\> which zip
/c/app/oracle/client11g/product/11.2.0/client/bin/zip
Then if you test it in irb:
irb(main):004:0> _, _, status = Open3.capture3('which zip')
=> ["/c/app/oracle/client11g/product/11.2.0/client/bin/zip\n", "", #<Process::Status: pid 10944 exit 0>]
You can see that the executable was found and success state is indicated by the 0. The variable status holds the return message - status => #<Process::Status: pid 10944 exit 0>
I have the which program from dev_kit:
c:\>which which
/c/prg_sdk/ruby/dev_kit/bin/which

Odd error when trying to run Tux in Sinatra (error: undefined method `needs_migration?')

I'm trying to run Tux in a Sinatra app, but I keep getting this error:
undefined method `needs_migration?' for ActiveRecord::Migrator:Class
I've tried running bundle update and a lot of other fixes, but nothing is working. Does anyone know what this error means and how to solve it?
I had some left over code in config.ru that I had to remove:
if ActiveRecord::Migrator.needs_migration?
raise 'Migrations are pending. Run `rake db:migrate` to resolve the issue.'
end
Check your project for the this if you're using ActiveRecord > 5.0

Capistrano error: 'Could not find form_data-0.1.0 in any of the sources' while deploying

I have a rails application on the dev server and I deleted the shared folder while attempting to make some changes. When I'm trying to redeploy the application, I get the following error on Capistrano.
servers: ["xx.xxx.xxx.223"] [xx.xxx.xxx.223] executing command
** [out :: xx.xxx.xxx.223] Could not find form_data-0.1.0 in any of the sources
command finished in 41821ms
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/apps/SITENAME/releases/20150507165055; true"
I have tried bundle install --deployment and I still get the same error
Could not find form_data-0.1.0 in any of the sources
Any help would be greatly appreciated.
This could be caused by outdated Gemfile.lock file. Remove Gemfile.lock, run bundle install and try to start your app again.

delayed_job gem - NotImplementedError: fork is not available on this platform

I am using jruby (1.7.3 or 1.7.9), delayed_job (1.8.4), daemons (1.1.9) gems for my rails 2.3.17 application.
I am trying to start the delayed job server using command:
1. jruby script/delayed_job start
Error:
RuntimeError: ObjectSpace is disabled; each_object will only work with Class, pass -X+O to enable
each_object at org/jruby/RubyObjectSpace.java:173
daemonize at /home/user/projects/new_central_repo/mml/mml_services/vendor/gems/delayed_job-1.8.4/lib/delayed/command.rb:39
(root) at script/delayed_job:5
To resolve this error, I passed "-X+O" option & ran following command:
jruby -X+O script/delayed_job start
This has resolved "ObjectSpace is disabled" error but I am getting following error on local.
Error:
NotImplementedError: fork is not available on this platform
fork at org/jruby/RubyKernel.java:1880
safefork at /home/user/.rvm/gems/ext-jruby-1.7.9#jruby179-rails2317/gems/daemons-1.1.9/lib/daemons/daemonize.rb:11
call_as_daemon at /home/user/.rvm/gems/ext-jruby-1.7.9#jruby179-rails2317/gems/daemons-1.1.9/lib/daemons/daemonize.rb:43
start_proc at /home/user/.rvm/gems/ext-jruby-1.7.9#jruby179-rails2317/gems/daemons-1.1.9/lib/daemons/application.rb:259
start at /home/user/.rvm/gems/ext-jruby-1.7.9#jruby179-rails2317/gems/daemons-1.1.9/lib/daemons/application.rb:296
run at /home/user/.rvm/gems/ext-jruby-1.7.9#jruby179-rails2317/gems/daemons-1.1.9/lib/daemons/controller.rb:70
run_proc at /home/user/.rvm/gems/ext-jruby-1.7.9#jruby179-rails2317/gems/daemons-1.1.9/lib/daemons.rb:197
call at org/jruby/RubyProc.java:290
call at org/jruby/RubyProc.java:224
catch_exceptions at /home/user/.rvm/gems/ext-jruby-1.7.9#jruby179-rails2317/gems/daemons-1.1.9/lib/daemons/cmdline.rb:109
run_proc at /home/user/.rvm/gems/ext-jruby-1.7.9#jruby179-rails2317/gems/daemons-1.1.9/lib/daemons.rb:196
daemonize at /home/user/projects/new_central_repo/mml/mml_services/vendor/gems/delayed_job-1.8.4/lib/delayed/command.rb:45
times at org/jruby/RubyFixnum.java:280
daemonize at /home/user/projects/new_central_repo/mml/mml_services/vendor/gems/delayed_job-1.8.4/lib/delayed/command.rb:43
(root) at script/delayed_job:5
Anyone can help me to resolve this error.
Locally I am able to start my server using "jrake jobs:work" command but I am not whether I can use "jrake jobs:work" instead of "jruby script/delayed_job start".
Thanks.
You cannot use delayed_job on jruby because it relies on Fork which is not available in jruby.

Error executing Ruby in Jenkins

I'm running Jenkins ver. 1.537 on Win7 64.
I'm trying to run a Ruby script in Jenkins using the "Execute Ruby script" build function.
The command is C:/autotest/Ultrapos_FX2-3/lib/testout.rb.
The script I'm trying to run is a simple hello world type thing:-
begin
puts 'TEST OUTPUT'
end
I can run this sucessfully from the command prompt, but Jenkins gives me the following error:-
Started by user anonymous
Building in workspace C:\Program Files (x86)\Jenkins\jobs\ruby\workspace
[workspace] $ ruby -v C:\Users\ithomp\AppData\Local\Temp\hudson8549990801552818192.rb
ruby 2.0.0p247 (2013-06-27) [i386-mingw32]
C:/Users/ithomp/AppData/Local/Temp/hudson8549990801552818192.rb:1: syntax error, unexpected tIDENTIFIER, expecting end-of-input
C:/autotest/Ultrapos_FX2-3/lib/testout.rb
^
Build step 'Execute Ruby script' marked build as failure
Finished: FAILURE
It seems that Jenkins is not executing the script that I'm specifing and instead calling some temp file.
Any ideas as to what the issue is?.
Thanks.
Ian.

Resources