Autoscaling workers for delayed_job in Rails 3 - ruby-on-rails

I've been using collectiveidea's fork of delayed_job as a gem in my Rails 3 app, and it's working fine. I'm now looking for a solution to autoscale workers, specifically for Heroku. I've given pedro's fork a try but since it's written for Rails 2, using it throws lots of errors and warnings about deprecated methods and I haven't been able to get it to work successfully.
Is there a working solution for Rails 3 delayed_job with autoscaling workers?

You might want to take a look at workless, it's one of the only Rails3 worker autoscalers I've seen at this point.

Specifically for heroku, check out "HireFire - The Heroku Worker Manager" and hirefireapp service:
https://github.com/meskyanichi/hirefire - open source
http://hirefireapp.com/ - service in public beta now

I've started working on a gem called Komodo to perform that very same task for un upcoming project at work. However, since we've only just started on the project, the gem is still very, very early - and untested.
I should see some consistent updating over the next couple of weeks though - would certainly appreciate any feedback or contributions! :)

Related

Puma 2.9.2 and rufus-scheduler 3.0.3 incompatibility

I´m using Rufus Scheduler 3.0.3 in a Ruby on Rails 4.1.4 web app and it´s working great with Unicorn. I moved to Puma and it´s great but I have realized Rufus is not working with Puma (daemonized).
I have read this issue #183 (comment) https://github.com/puma/puma/issues/183#issuecomment-59386038 that is closed for an earlier version, but it´s still not working and not clear to me if there is already a fix for it.
I don´t know if there is a workaround in the meantime.
UPDATE: There are not much logs to display, my rufus scheduler tasks are working when running with Unicorn, but If I change the server to Puma, it doesn´t run any automated task on my laptop. Even there is not any log to show.
I just add my current Rufus scheduler file:
task_scheduler.rb:
begin
require 'rufus-scheduler'
scheduler = Rufus::Scheduler.new
#Secretary responsible for executing events every 60 seconds.
scheduler.every '60s' do
Secretary.executeEvents
end
# Statistics (Owner) calculation every 1 day.
scheduler.every '24h' do
StatisticsCalculator.updateOwnerStatistics
end
end
Am I missing any configuration?
On the Puma side, I just have this config file config/puma/development.rb with only this:
stdout_redirect 'log/puma.stdout.log', 'log/puma.stderr.log', true
I don´t set up any workers, etc...
No, it works.
I packaged this sample project for you:
https://github.com/jmettraux/for_rober
Rufus-scheduler 3.0.3 schedules just fine with Puma 2.9.2 (Ruby 1.9.3 on Debian GNU/Linux).
Thanks for not blaming other people's work without facts.
If there really is an issue, I suggest you go and read http://www.chiark.greenend.org.uk/~sgtatham/bugs.html, then read it again, three times. It's most surely available in your native language. Then, if you really think rufus-scheduler is the culprit, go and open a detailed issue report at https://github.com/jmettraux/rufus-scheduler/issues Beware posting crappy "it doesn't work" material, it'll earn you only negative reactions.
UPDATE:
I strongly suggest you clone my mini-project on your machine and try it, then report the results here in the comments. The details are in the README.md of the project.
UPDATE:
Roberto is trying to get this issue solved in parallel, directly at https://github.com/puma/puma/issues/607
Finally, it looks there was an small issue. It has been kindly fixed by the Puma guys.
Please, see:
https://github.com/puma/puma/issues/607

Ruby on Rails not rendering views when downgrading from version 3 to 2

I am in the middle of putting up my Ruby on Rails app to a live server but have to downgrade from version 3 to 2 because that is all my shared hosting provider supports. I was able to adapt my models, controllers and routes without much problem. The problem I am having is with the views rendering.
I went through the process of creating a default layout for each controller as Rails 2 requires. When I run the app on the server, it starts just fine and the smokescreen index.html is visible but if I delete that and try to see the real app, all I get are broken links and files that are unable to load according to the browser.
I am sure this is an issue due to the downgrade. Any ideas on what I am doing wrong?
Doing a downgrade from Rails 3 to Rails 2 seems to me like a crazy thing to do for many reasons:
1) Rails 4 is already released. You should be looking to upgrade instead of downgrading.
2) There are many hosts out there that offer amazing services and even some free. Heroku is a great place to start if you don't want to manage your own server.
3) Rails 3 was almost a complete rewrite of the way Rails worked. This includes the addition of the Assets Pipeline which is a blessing in terms of development.
With that said, if you're still looking to downgrade, I would try to revert the steps found in many Upgrading Rails 2 to Rails 3 tutorials out there.
They are a bit long and many steps required to put here but a simple google search will yield many great resources. Here's a Railscasts http://railscasts.com/episodes/226-upgrading-to-rails-3-part-2

Private pub on heroku

I am developing a chat application using rails 3.2.12 and a great gem called private pub, for which you can find a screencast here. It is built on top of faye and enables you to easily build real time chats by pushing messages.
Now, deploying it on heroku actually is not that simple with private pub. Apparently, you have to set up another app for the faye channel and then subscribe to that channel from your other app.
This is all very confusing. Neither private pub nor faye have anything about deployment on heroku in their documentation. I have found these two links:
Private Pub on Heroku | Rails 3
http://webprogramming29.wordpress.com/2013/02/15/setup-privatepub-or-faye-on-heroku/
However, I don't really understand them since they start at a more advanced level.
Has anyone of you ever deployed a private pub/faye app on heroku and can give a step by step guide? Thanks!
You can checkout my sample chat at github https://github.com/Hareramrai/batkaro.
You can also checkout private_pub server code at github https://github.com/Hareramrai/fayeserver .
If someone is looking for a more up to date answer, I just released a gem that enables real time behavior in a Rails app:
https://github.com/dchacke/entangled
It sounds like, from the articles that you linked, that you need to have two web processes running. One for the normal web server, and one for the Faye server.
It may be easier to have two Heroku apps rather than trying to get each running within the same app.

Background Job Manager for Rails 3

Does anyone know of a background job manager that works with Rails 3? I have heard of Starling and Workling but I do not see a fork for Rails 3.
I used this article to get delayed_job (a common rails 2 gem for queueing jobs to be done later) running on rails 3. The collectiveidea branch of delayed_job has rails 3 support and works great.
Are you looking for a background-job worker ?
for simple usage i suggest delayed_job
https://github.com/collectiveidea/delayed_job/
Resque instead is more powerfull (It's used for github background job) but complicated.
https://github.com/defunkt/resque
bye
take a look at the railscast: beanstalkd and stalker: http://railscasts.com/episodes/243-beanstalkd-and-stalker
spawn is fine if you just want to run some code in a seperate thread and just forget about it.
https://github.com/tra/spawn

How can I make my Ruby on Rails 2.3.4 application "Rails 3-ready"

I'm developing an application with Ruby on Rails that I want to maintain for at least a few years, so I'm concerned about the next version coming up soon.
Going from Rails 1 to Rails 2 was such a big pain that I didn't bother and froze my gems and let the application die, alone, in the dark.
On this project I don't want to do that. First because this new version looks awesome, but also because this application may turn into a real product.
How can I prepare my application so that it will be upgradable with as little changes as possible.
How time consuming do you think switching version will be?
And what about my server? Deployment?
I'm already looking at deprecation notices... what else can I do?
The best thing you could do would be to follow development of Rails 3 via blogs and the Github repository and keep up a copy of your app along with it.
The official Ruby on Rails blog is updated with "What's new in Edge" posts every once in awhile. There are other blogs that often write about new things in edge as well. Larger features are often highlighted in these blogs, so you know about all the cool new features you can play with.
I'm not sure how close Rails 3 is to release (last I heard the core team was talking about a release at RailsConf 2009 in May), but you can always freeze the edge version of Rails into your application and just see what breaks. If you are using git, or another DVCS, you might make a branch specifically for Rails 3 and periodically update Rails to the latest edge code. Just be aware that edge Rails is a moving target so things in your app may break or fix themselves as you are pulling in newer Rails code.
Update:
Jeremy McAnally has a ton of info on upgrading from Rails 2 to Rails 3 on his blog.
http://omgbloglol.com/
I don't think there is going to be a major problem. Going off what was said in that initial report the Rails team realized that they can't do a major rewrite like they did from 1 to 2.
They even say:
I’m sure there’ll be some parts of Rails 3 that are incompatible, but we’ll try to keep them to a minimum and make it really easy to convert a Rails 2.x application to Rails 3.
I would be more concerned going from Merb to Rails 3.
The single most important thing you can do to make it easy to migrate to a new version of rails is to have a comprehensive test suite. Without a good test suite, I would never have the confidence that the new version of rails hasn't broken something in my app. On the current Rails app I'm working on, we started on Rails 2.1.1 back in October of 2008. Since then, we've migrated to Rails 2.1.2, 2.2.2, 2.3.2, 2.3.3 and now 2.3.4. I did the migrations to 2.3.2, 2.3.3 and 2.3.4...and for the 2.3.2 and 2.3.3 upgrades, we had some failing tests that alerted us to problems we would not have discovered without having such a good test suite. The failing tests actually alerted us to a regressive bug in rails that there was a patch for on the Rails lighthouse but that was not included in the release (since it was discovered, right after the release).
Once you've got that test suite in place, just stay current with each rails release (waiting a couple weeks to upgrade is fine, just don't skip any of the releases).
Yehuda Katz (a member of the Rails core team) has stated that there will most likely be a transitional release, containing deprecation warnings and such.
So as long as you have a good test suite to expose the inevitable upgrade problems, and stay current with the Rails release, the migration to Rails 3 should not be too difficult.
As simple as:
One
Two
Three
Great screencasts from Ryan Bates.
For preparing your application, the best way it what Jared said. Follow the Rails3 development.
For the time consuming, I think it depends of how you've followed the rails3 development before it's release.
And for the deployment, it shouldn't take too much problems. Rails 3 will be using Rack. So you can start it with mongrel, passenger or any server/gateway it shouldn't give you any problem.
There are some major changes in Rails 3, I posted about my experience upgrading my app to Rails 3 here: http://rails3.community-tracker.com/permalinks/5/notes-from-the-field-upgrading-to-rails-3
A good start in preparing would be to migrate over to using bundler. And doing a very deep review of strings that will go through the new XSS protection scheme.
There are going to be some automated compatibility checkers. Also, keep an eye on http://www.railsplugins.org/ so that you know if the libraries you depend on are going to be upgraded. The Rails Core team seems to be giving a lot of advance notice to the community this time around, so any lib that is actively maintained should be good to go.
Just do one thing
take a backup of your old version project first and then
on terminal(command prompt) write
rails new path/of/the/project
for example if my 2.3.* project is at home/rails_projects/myproject then
rails new home/rails_projects/myproject
or
cd home/rails_projects
rails new myproject
It will ask if there is any modifications done in any /config or other files. Do appropriate.

Resources