I get the following error when I run my task via DelayedJob:
closed stream
/usr/lib/ruby/1.8/drb/drb.rb:961:in `select'
/usr/lib/ruby/1.8/drb/drb.rb:961:in `alive?'
/usr/lib/ruby/1.8/drb/drb.rb:1211:in `alive?'
/usr/lib/ruby/1.8/drb/drb.rb:1168:in `open'
/usr/lib/ruby/1.8/drb/drb.rb:1166:in `each'
/usr/lib/ruby/1.8/drb/drb.rb:1166:in `open'
/usr/lib/ruby/1.8/drb/drb.rb:1163:in `synchronize'
/usr/lib/ruby/1.8/drb/drb.rb:1163:in `open'
/usr/lib/ruby/1.8/drb/drb.rb:1092:in `method_missing'
/usr/lib/ruby/1.8/drb/drb.rb:1110:in `with_friend'
/usr/lib/ruby/1.8/drb/drb.rb:1091:in `method_missing'
/usr/lib/ruby/gems/1.8/gems/acts_as_ferret-0.4.3/lib/remote_index.rb:31:in `<<'
/usr/lib/ruby/gems/1.8/gems/acts_as_ferret-0.4.3/lib/instance_methods.rb:90:in `ferret_update'
...
From the error its obvious that delayed_job could not find the ferret_server. However, when I run this SAME task from console in production mode, it works fine. Any ideas how I can ensure that delayed_job has:
really loaded the production environment. I set RAILS['ENV]] = 'production' in the script/delayed_job to ensure this. (I guess this should be good)
got ferret configured via models?
This happened to me too. You need to disable ferret from indexing during the running of the delayed job.
In your worker definition (something like RAILS_ROOT/lib/worker.rb), and given a model called Post, you should include a line like this:
class Worker < Struct.new(:stuff)
def perform
Post.disable_ferret
<do some stuff>
.
.
.
end
end
Related
I'm trying to run Rails on JRuby 1.7.3 in userspace on Solaris and I get this error when running rake db:create.
-bash-3.2$ rake db:create
rake aborted!
undefined method `error' for #<ActiveRecord::JDBCError:0x109d7b8>
org/jruby/RubyArray.java:1613:in `each'
org/jruby/RubyProc.java:249:in `call'
org/jruby/RubyArray.java:1613:in `each'
org/jruby/RubyArray.java:1613:in `each'
org/jruby/RubyKernel.java:1046:in `load'
Tasks: TOP => db:create
(See full trace by running task with --trace)
I have looked at the JRuby source for this line, but I'm pretty far out of my depth on this and I'm not sure what's going on. Has anyone seen this before?
I haven't run on that kind of error before, but just to double-check .. have you used jruby specific gem for making a connection to databases:
https://github.com/jruby/activerecord-jdbc-adapter
If not, try using that instead the ones you have been using so far for "regular" ruby
I just run into this error. It seems like a bug in Rails. Your idea of inspecting the source for that line was a good one. I went there and changed $stdout.print error.error for just $stdout.print error because the error method didn't seem defined.
That revealed the actual error:
#<ActiveRecord::JDBCError: Access denied for user 'root'#'localhost' (using password: YES)>
In my case, I was mispelling the username key in the config/database.yml file, so it would assume the root user, but the password would be wrong.
Is there a special place for cronjobs in rails? I couldn't find information on this subject, the only examples out there are to execute Model.some_method
I created a class Crawler, with a method run, and tried different places for it (including app/models), but I keep getting this error:
$ rails runner -e development 'Crawler.run'
/usr/local/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/commands/runner.rb:53: undefined method `run' for Crawler:Class (NoMethodError)
from /usr/local/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/commands.rb:64:in `eval'
from /usr/local/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/commands/runner.rb:53
from /usr/local/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/commands.rb:64:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/railties-3.2.1/lib/rails/commands.rb:64
from script/rails:6:in `require'
from script/rails:6
class Crawler
def run
puts 'bla'
end
end
As you can see, it can't find the method 'run'.
If I put it inside /scripts I get this: uninitialized constant Crawler (NameError), so this is probably not what I want.
Any ideas?
note. I'm on rails 3
You're calling an instance method on class level.
Rewrite like this:
class Crawler
def self.run
puts 'bla'
end
end
To answer your initial question, there is no real dedicated place but I usually create a crons folder under app.
Regarding rake tasks, they are supposed to live in /lib but it's really up to you.
I encourage you to use the whenever gem. It allows you to set up tasks in a schedule.rb file as follows:
every 3.hours do
runner "MyModel.some_process"
rake "my:rake:task"
command "/usr/bin/my_great_command"
end
In schedule.rb file, the statement:
require "#{RAILS_ROOT}/config/environment.rb"
every "10 10 2 * * *" do
command "mysqldump -u #{#db_username} -p#{#db_password} --single-transaction #{#db_name} > #{#backup_Path}/#{#db_name}.sql 2> log/error_crontab.log"
end
When i try to execute the whenever cmd from terminal, getting the following error:
config/schedule.rb:48:in `initialize': uninitialized constant Whenever::JobList::RAILS_ROOT (NameError)
from /usr/local/lib/ruby/gems/1.9.1/gems/whenever-0.7.0/lib/whenever/job_list.rb:19:in `instance_eval'
from /usr/local/lib/ruby/gems/1.9.1/gems/whenever-0.7.0/lib/whenever/job_list.rb:19:in `initialize'
from /usr/local/lib/ruby/gems/1.9.1/gems/whenever-0.7.0/lib/whenever.rb:16:in `new'
from /usr/local/lib/ruby/gems/1.9.1/gems/whenever-0.7.0/lib/whenever.rb:16:in `cron'
from /usr/local/lib/ruby/gems/1.9.1/gems/whenever-0.7.0/lib/whenever/command_line.rb:40:in `run'
from /usr/local/lib/ruby/gems/1.9.1/gems/whenever-0.7.0/lib/whenever/command_line.rb:7:in `execute'
from /usr/local/lib/ruby/gems/1.9.1/gems/whenever-0.7.0/bin/whenever:38:in `<top (required)>'
from /usr/local/bin/whenever:19:in `load'
from /usr/local/bin/whenever:19:in `<main>'
i am using the require statement to get the dynamic values from the form to schedule the job. Please help to solve this issue?
Note: i have seen the following stackoverflow queries:
How to detect Rails environment inside whenever
Following this thread to get dynamic values, but facing problem with require statement.
Rails - Whenever gem - Dynamic values
Ruby/Rails - Whenever gem - Loop cron tasks
config file in schedule.rb with Rails Whenever gem?
Whenever doesn't require or depend on Rails at all, so when it runs, RAILS_ROOT is not defined, however because whenever's schedule.rb is generally kept in /config/schedule.rb, we can make an assumption that it is in a rails project, and set our own RAILS_ROOT like this:
# in schedule.rb
RAILS_ROOT = File.dirname(__FILE__) + '/..'
Edit: in the case that you actually need Rails loaded, do this:
# in schedule.rb
# this will require config/environment and load your entire rails environment
require File.expand_path(File.dirname(__FILE__) + "/environment")
The whenever developer already answered this question, check this out https://github.com/javan/whenever/issues/81
Javan Whenever no longer attempts to load your Rails environment. However, it does automatically set a path variable to the directory whenever was executed from. This should work just the same:
set :output, "#{path}/log/cron.log"
In Rails 4 try with:
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
in your schedule.rb file.
This way you also have access to all your active-record models and initializers.
I originally posted a question relating to this problem on serverfault.com: https://serverfault.com/questions/152587/apache-mod-proxy-to-another-server
I have since realized that this is not an issue with my server setup, but my rails application. I have set this application up server-wise the exact same as another functioning rails app I have running on the same server. When I start the server my mongrel.log looks like this:
** Daemonized, any open files are closed. Look at /var/www/osuwebdev/tmp/pids/mongrel.pid and log/mongrel.log for info.
** Starting Mongrel listening at 0.0.0.0:8080
** Starting Rails with production environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).
** Rails signals registered. HUP => reload (without restart). It might not work well.
** Mongrel 1.1.5 available at 0.0.0.0:8080
** Writing PID file to /var/www/osuwebdev/tmp/pids/mongrel.pid
When I load a page this pops up in the log:
Wed Jun 30 19:46:10 +0000 2010: Error calling Dispatcher.dispatch #<NoMethodError: undefined method `[]' for nil:NilClass>
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/cgi.rb:108:in `send_cookies'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/cgi.rb:136:in `out'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/http_response.rb:65:in `start'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/cgi.rb:135:in `out'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:81:in `process'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:159:in `process_client'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:158:in `each'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:158:in `process_client'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:285:in `run'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:285:in `initialize'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:285:in `new'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:285:in `run'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:268:in `initialize'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:268:in `new'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:268:in `run'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/configurator.rb:282:in `run'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/configurator.rb:281:in `each'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/configurator.rb:281:in `run'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:128:in `run'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/command.rb:212:in `run'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:281
/usr/local/bin/mongrel_rails:19:in `load'
/usr/local/bin/mongrel_rails:19
I cannot figure out what is different about this app that may cause this issue.
I believe this is a weird combination of bugs in Rack, Mongrel, and Rails.
Save this ruby code in your app to config/mongrel.rb: http://gist.github.com/471663
In your config/environment.rb, at the very end of the file add:
require File.join(File.dirname(File.expand_path(FILE)), 'mongrel')
In that same file add this line in the Rails::initializer.run block:
config.gem "mongrel"
Longer explanation of the problem here: https://rails.lighthouseapp.com/projects/8994/tickets/4690-mongrel-doesnt-work-with-rails-238
This has definitely worked for a Rails 2.3.8 app, though I patched it slightly differently than described above.
Do you still see the problem on subsequent GET requests? I had a similar problem where my Rails app would run fine under WEBrick but not under Mongrel but found somewhere on the internets (here's a link that shows a similar version of the problem) that older versions of Mongrel mishandle the first request to the page but handle subsequent requests ok.
The workaround we put in was that whenever we started the app, we'd have curl perform a GET on the app to 'prime' Mongrel.
This is usually a fail reading a yaml file for config. It has set up a config object to get values from and the entry in the yaml file for your environment isn't there so the object is nil.
Are you running any gems that have a yaml file that maybe isn't set up for development?
I don't know why going back to 2.3.5 would help - it might be that it loads things in a different order and the config information is available.
I am getting a really strange error from ActiveResource. I have a method that calls another system to get a list of products. The list is quite large and takes about 3 minutes to generate and transfer. Since this is really only a once a day kinda thing I built a rake task to run it. In production whenever I run the rake task it fails with a 500 error. Here is some sample output
$ time RAILS_ENV=production rake api:sync
rake aborted!
Failed with 500 Internal Server Error
(See full trace by running task with --trace)
real 2m1.753s
user 0m1.188s
sys 0m0.188s
Then I tried to use script runner:
$ RAILS_ENV=production script/runner 'Product.synchronize!(ProductManager::Product.find_valid_products)'
/var/www/apps/api/releases/20091202203413/vendor/rails/railties/lib/commands/runner.rb:48: Failed with 500 Internal Server Error (ActiveResource::ServerError)
from /usr/local/lib/ruby/1.8/net/protocol.rb:133:in `rbuf_fill'
from /usr/local/lib/ruby/1.8/timeout.rb:62:in `timeout'
from /usr/local/lib/ruby/1.8/timeout.rb:93:in `timeout'
from /usr/local/lib/ruby/1.8/net/protocol.rb:132:in `rbuf_fill'
from /usr/local/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
from /usr/local/lib/ruby/1.8/net/protocol.rb:126:in `readline'
from /usr/local/lib/ruby/1.8/net/http.rb:2020:in `read_status_line'
from /usr/local/lib/ruby/1.8/net/http.rb:2009:in `read_new'
... 17 levels...
from /var/www/apps/api/releases/20091202203413/vendor/rails/railties/lib/commands/runner.rb:48
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from script/runner:3
However if I jump into the console to run it, everything is fine:
$ script/console production
Loading production environment (Rails 2.3.5)
>> Product.synchronize!(ProductManager::Product.find_valid_products); nil # prevent dump to console
=> nil
>>
I suspected it was a timeout, so I set the timeout value to 5 minutes on the ProductManager::Product class, but that had no effect. The interesting thing is that when I run via rake or script/runner the error happens occurs at 2 minutes and 1 second without fail. In development and staging there is no issue. Does production of ActiveResource have some kind of hidden 2 minute override I can't find?
In case you didn't get it from the traces, we are using Rails 2.3.5 frozen into the application. Thanks for you help
Peer
Turns out it was an Apache setting. The RequestTimeout in the httpd.conf file was 120 seconds. Once we upped that everything was fine.