Code run after Rails loading?

I have a periodic task that needs to be done once a minute (using delayed_job). I would like Rails to automatically queue as soon as it finishes loading, if one such task is not already present on the system.

What suits me to run the code at the end of the entire Rails bootstrap? Someone suggested config / environment / development.rb (or another environment), but delayed_job gives me ActiveRecord problems when I queue jobs from there.

I consulted http://guides.rubyonrails.org/initialization.html and there seems to be no clear place for such code.

Is such a deployment possible after deployment, perhaps externally for my application code, perhaps using rake or other methods? Any suggestions?

Thanks!

+8
ruby-on-rails ruby-on-rails-3 delayed-job
source share
3 answers

Regarding http://guides.rubyonrails.org/initialization.html , sorry, we work a lot to rewrite it. For your problem, I would try with config.after_initialize in your .rb application

 def after_initialize(&block) ActiveSupport.on_load(:after_initialize, :yield => true, &block) end 
+8
source share
+3
source share

You have two options:

1) add it to the initializer directory, and this should be fine.

2) add it to the very end of application.rb, it will be less clean, but at that moment it will have things like initializers, p if 1) it fails due to problems with AR 2)

+2
source share

All Articles