Heroku run process using JRuby 1.7 and Rails 3.2 hangs - ruby-on-rails

I was able to get the web process on heroku running with JRuby and trinidad. I am using this in my Gemfile, which seems to be the best practice over a custom heroku buildpack at this point:
ruby "1.9.3", :engine => "jruby", :engine_version => "1.7.0"
However, in trying to load the database (or connect to the rails console) via:
heroku run rake db:schema:load
or
heroku run console
The command just hangs. Tailing the heroku logs I see the process starting up and completing without error, but I never get any output back on the local command line and it just hangs.
2012-11-16T16:02:46+00:00 heroku[api]: Starting process with command `bundle exec rake db:schema:load`
2012-11-16T16:02:51+00:00 heroku[run.1]: Awaiting client
2012-11-16T16:02:51+00:00 heroku[run.1]: Starting process with command `bundle exec rake db:schema:load`
2012-11-16T16:02:51+00:00 heroku[run.1]: State changed from starting to up
2012-11-16T16:02:51+00:00 heroku[run.1]: State changed from starting to up
2012-11-16T16:03:21+00:00 heroku[run.1]: State changed from up to complete
2012-11-16T16:03:21+00:00 heroku[run.1]: State changed from up to complete
2012-11-16T16:03:21+00:00 heroku[run.1]: Process exited with status 0
I'm guessing I need to do add a rake and console item in the Procfile and tried some various combinations but nothing was working. It always hangs. I also didn't see anyone else's Procfile for JRuby including these items.

This turned out to be an issue with running the heroku gem from within JRuby. Running the commands via heroku toolbelt from outside of JRuby (MRI 1.9.3) works fine.

Related

Heroku-Buildpack-Multi causing app to crash

I'm have a Rails 4 app on Heroku that I'm trying to deploy with two buildpacks. I'm not sure if I'm missing a step or if there is a bug, but when I push the code, the app deploys successfully. When I open it however, it crashes.
I've tried using the command heroku buildpacks:set https://github.com/bobbus/image-optim-buildpack.git and heroku buildpacks:set https://github.com/ddollar/heroku-buildpack-multi.git, but am only able to set one at a time, not both. It doesn't seem to matter which one I set, the app always crashes. Searching through the logs, I see the following:
heroku[web.1]: State changed from crashed to starting
heroku[web.1]: Starting process with command `bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}`
app[web.1]: bash: bundle: command not found
heroku[web.1]: Process exited with status 127
heroku[web.1]: State changed from starting to crashed
I'm no expert on bundler, but it seems like for some reason it's not recognizing the bundle command in my Procfile.
Here is my Procfile, which I should note has worked perfectly up until now.
web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}
I've also tried clearing out the buildpacks (heroku buildpacks:clear) and creating a .buildpacks file instead, but that yielded the same error.
Here is my .builcpacks file:
https://github.com/ddollar/heroku-buildpack-multi.git
https://github.com/bobbus/image-optim-buildpack.git
The documentation in the Heroku Dev Center and on the buildpacks themselves is pretty sparse as far as I can tell.
Using the .buildpacks multi manager isnt required because Heroku supports multiple buildpacks natively by passing --index when setting a buildpack for example:
heroku buildpacks:set https://github.com/heroku/heroku-buildpack-ruby --index 1
heroku buildpacks:set https://github.com/shunjikonishi/heroku-buildpack-ffmpeg --index 2
Change something in your git repo && then do a -> git push heroku master
The Deploy will detect your buildpacks and will run them. To check what buildpacks are currently set in your app run: heroku buildpacks
If the two build packs you listed are the only two you're loading, I think you're missing the Ruby buildpack, which is where the "bundler" is defined:
https://github.com/heroku/heroku-buildpack-ruby
Note: If I were debugging this, I would ditch the buildpack-multi, and use just the Ruby buildpack to see if you can get that through the bundler error, then try to load another buildpack, and so on.
I see what you mean about the documentation. Pretty weak. Let me know if this helps.

Heroku deployment rake db:create/migrate error

I am following Hartl's ROR tutorial and I am trying to get my DB working on Heroku, but to no avail. When I run the following commands:
heroku run rake db:create
or
heroku run rake db:migrate
I get the following errors:
Running `rake db:create` attached to terminal... up, run.5477
/usr/bin/env: ruby2.2: No such file or directory
Running `rake db:migrate` attached to terminal... up, run.5562
/usr/bin/env: ruby2.2: No such file or directory
I am using postgresql for development and production. Here is my latest commit https://github.com/Euklidian-Space/sample-app
Here are the heroku logs:
2015-07-30T16:42:48.956556+00:00 heroku[api]: Starting process with command `bundle exec rake db:migrate` by gabriel.grover#gmail.com
2015-07-30T16:42:53.039994+00:00 heroku[run.5562]: Awaiting client
2015-07-30T16:42:53.090027+00:00 heroku[run.5562]: Starting process with command `bundle exec rake db:migrate`
2015-07-30T16:42:53.343439+00:00 heroku[run.5562]: State changed from starting to up
2015-07-30T16:42:55.633768+00:00 heroku[run.5562]: State changed from up to complete
2015-07-30T16:42:55.618985+00:00 heroku[run.5562]: Process exited with status 127
In your bin/bundle, bin/rake, bin/rails and bin/setup files, the first line of each reads #!/usr/bin/env ruby2.2. Change them all to #!/usr/bin/env ruby. Then try deploying again.

Delay Job Worker keeps turning off?

New to Rails and very new to Delayed Jobs.
Got one that's supposed to be triggered after 5 minutes. I finally got it to work so that if I run
rake jobs:work
in my terminal, the job starts up and works correctly. If I CTRL-C and exit that action in my terminal, the delayed job stops working correctly. This is one thing on my local server and another on Heroku, where I have to start up the delayed job using
heroku run rake jobs:work
I looked into the new Heroku toolbelt and downloaded the gem they suggest for worker maintenance, foreman, but when I run "foreman start", I get this error
ERROR: procfile does not exist
I don't know what a procfile is, I'm afraid of breaking things after spending pretty much a day debugging my delayed_jobs actions, and I want to do this right to make sure it works instead of figuring out some hacky fix that breaks down later -- so I figured I should ask this question, however obnoxiously vague it may be.
Should I be using foreman for this? Or workless? (Saw that in another SO question). Where's my procfile? Should I do anything with it?
Thanks,
Sasha
You should be using a procfile to set up your Heroku processes, this is the standard method that Heroku uses to define and control the processes.
If you haven't utilised a procfile to this point everything will probably still work as Heroku adds some default processes when you push a Rails app, including both the web and worker processes. The default worker process is set to delayed job.
Foreman was developed in order to set up your local machine to use the same approach but, unlike the Heroku service, Foreman actually requires a procfile to be present to control the services that are started when Foreman is started as it doesn't know how to setup defaults.
I would suggest creating a procfile, placed in the root directory of your project, to ensure that your processes are set up and operating in the same manner on your local machine as on Heroku. If you want to mimic what Heroku sets up automatically you add the following to the procfile depending on whether you are using the Thin web server (which Heroku recommends) or not.
With Thin in your gemfile:
web: bundle exec thin start -R config.ru -e $RACK_ENV -p $PORT
worker: bundle exec rake jobs:work
Without a special web server (eg you are using webrick, the rails default):
web: bundle exec rails server -p $PORT
worker: bundle exec rake jobs:work
Once this file is in place you can run foreman on your local machine and it will start your web server and delayed_job workers automatically.
Running through this process will only impact starting delayed_job on the local machine. As you are running the exact same command bundle exec rake jobs:work as you are currently using there should be no impact on your dj actions in either locally or on Heroku. Obviously some testing is required to make suer this is actually the case.
Workless is designed to scale workers on Heroku so that you don't have to pay for them when there is no work available. It has no bearing on the procfile or defining how to actually start a dj worker process.
as far as I know, there are 2 version of delayed_job:
original(tobi's) https://github.com/tobi/delayed_job
collectiveidea's fork: https://github.com/collectiveidea/delayed_job
when using the collectiveidea version, you should start it as below:
# Runs two workers in separate processes.
$ RAILS_ENV=production script/delayed_job -n 2 start
I am not familiar with delayed_job on Heroku, please follow its instructions.

After heroku run rake db:migrate (cedar stack) - migration not happening

I'm trying to run heroku run rake db:migrate, but I get the following:
Running rake db:migrate attached to terminal... up, run.7
And that's it - Migration is not happening!
Although I have set up everything alright - development as sqlite3 and production as pg.
And previously all the migrations worked just fine. (rails 3.1. app )
I'm not sure what is happening here.
Here are the logs:
←[35m2012-01-08T11:25:22+00:00 app[run.8]:←[0m Awaiting client
←[35m2012-01-08T11:25:22+00:00 app[run.8]:←[0m Starting process with command `bu
ndle exec rake db:migrate`
←[35m2012-01-08T11:25:22+00:00 heroku[run.8]:←[0m State changed from starting to
up
←[35m2012-01-08T11:25:35+00:00 heroku[run.8]:←[0m State changed from up to compl
ete
←[35m2012-01-08T11:25:35+00:00 heroku[run.8]:←[0m Process exited
I don't see any errors.
Has anybody came across with something similar ?
Thanks!
The reason for this was simply because the migration has already happened automatically after pushing the updated app to heroku.

Resque on Heroku cedar stack Worker count still exists after the worker terminate

I have successfully run resque on heroku cedar stack and mount the interface on rails.
when I start the worker, Everything works fine. The worker process the job. But When i kill the worker, Resque still think that the worker is available. When I start another worker, it then think there are 2 worker but in fact there is only one running.
I also notice form here http://devcenter.heroku.com/articles/ps that heroku send SIGTERM when killing a worker and if that does not terminate then it send SIGKILL.
here is my worker logs
2011-08-11T02:32:45+00:00 heroku[worker.1]: Starting process with command `bundle exec rake resque:work QUEUE=*`
2011-08-11T02:32:46+00:00 heroku[worker.1]: State changed from starting to up
2011-08-11T02:33:58+00:00 heroku[worker.1]: State changed from up to stopping
2011-08-11T02:34:00+00:00 heroku[worker.1]: Stopping process with SIGTERM
2011-08-11T02:34:09+00:00 heroku[worker.1]: Error R12 (Exit timeout) -> Process failed to exit within 10 seconds of SIGTERM
2011-08-11T02:34:09+00:00 heroku[worker.1]: Stopping process with SIGKILL
2011-08-11T02:34:11+00:00 heroku[worker.1]: Process exited
I see that my process takes more then 10s to terminate. Is this have anything to do because I load up rails environment on the worker task ?
this is my rake task lib/tasks/resque.rake
require "resque/tasks"
task "resque:setup" => :environment
I just found out the problem, this happend when passing ENV on the rake task. like when passing QUEUE='*'.
Here is the issue more complete
https://github.com/defunkt/resque/issues/319#issuecomment-1789239
and the issue are still in discus at https://github.com/defunkt/resque/issues/368
any my temporary patch, that make resque only run all que.
https://github.com/yulrizka/resque
ahmy,
Based on your solution, I came up with one that doesn't involve forking resque.
I put this in resque.rake:
task "resque:setup" => :environment do
ENV['QUEUE'] = '*'
end
and put this in the Profile:
worker: bundle exec rake resque:work
and put this in the Gemfile:
gem 'resque', :git => 'git://github.com/defunkt/resque.git'

Resources