Good screencast but what a pity you didn't talk about mail notifications.
The code you show up is on god homepage, your explanation is a real bonus but I think it lacks a bit of "advanced use".
Never mind, I am a fan of your screencasts, it helps so much to improve my RoR skills that I just "want more" I guess ;)
I'm hoping someone is still looking at this comment thread that might be able to help.
I'm trying to add one additional field to the task (as used in the tutorial). Let's say I want to be able to mark a task as "Active" or not with a boolean value.
when I add
<%= task_form.text_field :task %>
<%= task_form.check_box :active %>
the form passes a "active" => "0" for each unchecked item as well as the "1" for the checked items. This gets all wonky and ends up creating extra rows with only the "active" column filled. Is there a way to make check_box work correctly here?
A Pastie for some detail on my situation:
http://pastie.org/288094
Maybe I'm just paranoid — but whats stopping God from dying? (if your possibly expecting your daemons to go down, it would be kind of ignorant to expect God to stay up 100% of the time I would think?)
Normally I'd agree with you, but inside of a block I'd say single letter variables are fine, since they have a very limited context. I suppose in a complicated example I'd also agree with you, but with every line starting the same way in the block, this seems like the closest you can get to DRY in a block context (correct me if I'm wrong).
Nick - Just take out the else statement, then in your view check to see if @projects is holding anything, if its no then display a no results message...
@Guillermo, that's a good question. On my setup it uses about 8 MB of RAM, so if you're running on a VPS with very limited memory you may want to use Monit.
@Francois, I'd just use one God process for the entire server (multiple Rails apps). This is one reason I prefixed the watch names with "mailit" so we could easily add other apps without conflict. It's easy to load as many config files as you need.
Then just run "god -c /path/to/all.god" to load them all.
@Ben, I agree in some sense. I encourage everyone who uses this kind of tool to closely monitor the logs and set up a notification to warn you when something goes down. If a process is having to restart constantly then that should be fixed.
That said, I think this still has a very important role. Think of it as the net under the trapezist. It's not part of the act, but it's there if the unthinkable happens.
Is it just me or does this seem like you are just sweeping the dirt under the rug?
If your background processes are consuming too much memory, or constantly shutting down, wouldn't it be smarter to find out why, instead of just having a script restart it?
Something like this just seems to promote bad programming practices / laziness.
Thanks for another great screencast. Question: if you have multiple rails projects on a given server, do you suggest running multiple instances of god (one for each rails application)? Or would you then move the config file outside of the rails config folder and place it somewhere else on the server and run only one instance of god?
I am trying to install the plugin and it keeps coming up with hanging during the installation. Here is the output:
removing: /Users/Tim/Code/Ruby/RainbowCube/vendor/plugins/subdomain-fu/.git
Initialized empty Git repository in /Users/Tim/Code/Ruby/RainbowCube/vendor/plugins/subdomain-fu/.git/
fatal: exec index-pack failed.
fatal: index-pack failed
~/Code/Ruby/RainbowCube$ remote: Counting objects: 26, done.
remote: Compressing objects: 100% (19/19), done.
Using this method account and group are saved by user is not. If build method is not capable of handling more than 1 level then how should i create the user ensuring the group_id is populated with the new group? Any help will be greatly appreciated.
As far as I know Daemons won't work on Windows, so you'd probably have to create a service and work through that (a much bigger problem than doing it the *nix way). I found this to give you a bit of help getting started, but really it should just tell you why it is better to use Linux or OS X for some things:
Ryan,
I was able to start the daemon fine, changed code while($running) loop and saw the changes. But now I can't stop or restart the daemon using lib/daemons/whatever_ctl stop command. I had to force kill the process from terminal to stop the daemon.
Thanks Ryan, great tutorial. I was trying to do it with the rakismet plugin but found it confusing. Your plugin seems easier and it comes with a screencast so that's easier!
Just a question, are you doing anything with the permalink attribute on the comments? Is that needed or is it optional?
Re: Starling install on windows. The problem was that there is no Windows binary yet for the latest version of eventmachine gem which is a dependency for starling. I have VC++ installed so it should compile, but anyway...I installed the previous version (which appears to be all Starling requires) and then installed Starling using --ignore-dependencies.
Now I am getting a syslog error when trying to start Starling. This is documented as being fixed in version 0.9.9 in Starling Readme, but I can't figure out how to install 0.9.9...I always get 0.9.8.
Hi, i am implementing this for my applicatino, and seem to be running into some problems because my page is shorter then my browser window and i am getting some negative numbers, which activate the checkScroll function when it doesnt have to be. Anybody run into this same issue? Any ideas on how to solve this? Thanks in advance.
@ Ryan Bates Jul 21, 2008 at 12:01
Quote: Instead of filling the controller up with the logic, make a custom model.
I don't agree with this statement you've made Ryan. Your rails casts are great, I really like the effort you put into the rails community, but business logic shouldn't be near the models. Imo, they are strictly for the storage and handling of data, nothing more. If you want to keep the controller free of business logic (which is awesome), custom modules.etc. I find better suit this requirement. Otherwise you're mixing the "roles" of MVC.
I just created a plugin called PassiveRecord that makes a lot of this stuff very easy. Check it out on Github: http://github.com/artofmission/passiverecord
I have some question regarding automated background jobs.
I am building an application which is getting some data from the remote RSS feed every 5 minutes. Then it checks some values and makes comparison of those values with user values. If condition is true e-mail is sent to the user.
Now, i am doing this every 5 minutes via cron job and rake.
Because of environment being loaded every time i am considering using starling+workling.
Someone already asked similar question here, about how to do starling jobs in a scheduled manner, and the answer was to "do" a sleep after the job is finished for let's say 5 minutes.
I am not a very good programmer nor specialist, but i doubt sleeping for 5 minutes or triggering action every 5 minutes is the same.
When i trigger the an action via cron it will allways be triggered at same time (0m, 5m, 10m etc...), however the job done with sleep will be allways run at different times, depending on how long it took it to run (0m, 5m20s, etc...), which is completely out of option for me :)
Please, correct if i got this wrong.
So, another solution i am thinking about is to create starling job which would be triggered with a cron job which would call a script with simulated http trigger of action (like when you click on deliver e-mail in your screencast).
As i said before i am not a specialist so my question is wether this is a stupid solution or what could be best.
Im trying to update Proyect-Users-role taking this approach. But i have an ActiveRecord::ReadOnlyRecord message. My assiciation table is projects_users and it has project_id, user_id, role_id as fields. How can this be done?
i've updated the README for workling. i also made the error messages much friendlier - if your starling isn't running on the correct port, workling will tell you where it's expected.
workling will now also function without the fiveruns memcache client, if you're runnign an older version of starling.
so go and grab the latest workling version and look at the README :)
I am getting the following error intalling Starling - is something else required to install on Windows?:
"gem install starling
Building native extensions. This could take a while...
ERROR: Error installing starling:
ERROR: Failed to build gem native extension.
Curious how you got your tasks to associate to the :project_id during your setter method .build code.
I have a product model which included product_photos, where i use attachment_fu to allow for the upload of the picture to the product_photos model. I can't associate the project_id in the setter method, and it isn't added during the .save method in create.
All that to say, ryanb, how did you save the project_id to each of the tasks? if you didn't how in god's name do you display three tasks to one project, if they aren't assoicated via the project_id field in the task model?
Hi, thx for the great tutorial, but i have some problems for with the request parameters the view sending to the controller:
i have a "voting" model which has a has_many "voting_timeslots". when saving the voting with one voting_timeslot it works great but adding more voting_timeslot i get "undefined method `vote_timeslotes=' for #<Voting:0x62c418c>" .
This is i think because of the request parameter sended to the controller, the hash isn't sorted:
Good screencast but what a pity you didn't talk about mail notifications.
The code you show up is on god homepage, your explanation is a real bonus but I think it lacks a bit of "advanced use".
Never mind, I am a fan of your screencasts, it helps so much to improve my RoR skills that I just "want more" I guess ;)
I'm hoping someone is still looking at this comment thread that might be able to help.
I'm trying to add one additional field to the task (as used in the tutorial). Let's say I want to be able to mark a task as "Active" or not with a boolean value.
when I add
<%= task_form.text_field :task %>
<%= task_form.check_box :active %>
the form passes a "active" => "0" for each unchecked item as well as the "1" for the checked items. This gets all wonky and ends up creating extra rows with only the "active" column filled. Is there a way to make check_box work correctly here?
A Pastie for some detail on my situation:
http://pastie.org/288094
Maybe I'm just paranoid — but whats stopping God from dying? (if your possibly expecting your daemons to go down, it would be kind of ignorant to expect God to stay up 100% of the time I would think?)
But very good episode Ryan, thanks!
@Zach,
Normally I'd agree with you, but inside of a block I'd say single letter variables are fine, since they have a very limited context. I suppose in a complicated example I'd also agree with you, but with every line starting the same way in the block, this seems like the closest you can get to DRY in a block context (correct me if I'm wrong).
Thanks for a great tutorial!!!
Is there a way to start god automatically with the rails application, without any need for for external commands?
Nick - Just take out the else statement, then in your view check to see if @projects is holding anything, if its no then display a no results message...
Simple question for noob.
I am trying to figure out the correct url for my capistrano deploy script for the local git repo this sc uses.
"git://localhost:3000/.git"?
Whatever i try gives me errors. I am on Leopard.
Nice work Ryan but single-letter variables are evil. They lack clarity and promote laziness.
Hi,
Yet another great cast.
Testing this on Centos 5 I had to do
script = "export RAILS_ENV=production && #{RAILS_ROOT}/script/workling_starling_client"
If I didn't the workling startup process just failed...
@Guillermo, that's a good question. On my setup it uses about 8 MB of RAM, so if you're running on a VPS with very limited memory you may want to use Monit.
@Francois, I'd just use one God process for the entire server (multiple Rails apps). This is one reason I prefixed the watch names with "mailit" so we could easily add other apps without conflict. It's easy to load as many config files as you need.
# all.god
load '/path/to/mailit.god'
load '/path/to/foo.god'
load '/path/to/bar.god'
Then just run "god -c /path/to/all.god" to load them all.
@Ben, I agree in some sense. I encourage everyone who uses this kind of tool to closely monitor the logs and set up a notification to warn you when something goes down. If a process is having to restart constantly then that should be fixed.
That said, I think this still has a very important role. Think of it as the net under the trapezist. It's not part of the act, but it's there if the unthinkable happens.
might i also add...jesse newland has created an awesome rails plugin called san_juan. use it for capistrano god recipes.
get it here: http://github.com/jnewland/san_juan/tree/master
way to step up ryan and create an excellent railscast on God process monitoring. more people need to become familiar with its awesomeness.
Is it just me or does this seem like you are just sweeping the dirt under the rug?
If your background processes are consuming too much memory, or constantly shutting down, wouldn't it be smarter to find out why, instead of just having a script restart it?
Something like this just seems to promote bad programming practices / laziness.
Am I too late to add the obligatory "Of *course* God isn't compatible with Windows!" comment?
I should add I'm using Rails 2.1
Great screencast! God is one of those tools that I've looked at, but haven't really had a reason to use yet, but wanted to.
Thanks for another great screencast. Question: if you have multiple rails projects on a given server, do you suggest running multiple instances of god (one for each rails application)? Or would you then move the config file outside of the rails config folder and place it somewhere else on the server and run only one instance of god?
#20
Thanks Carl.
Great as always.. keep up the good work. I like how you do 2-4 relating screencasts in row yet still keep them independent.
How much is the amount of ram used by god, and how much it is increased with the addition of more procesess.
I come from monit, and i am asking why could god be better (more than is ruby).
Thanks.
Thanks for the great rails cast.
I am trying to install the plugin and it keeps coming up with hanging during the installation. Here is the output:
removing: /Users/Tim/Code/Ruby/RainbowCube/vendor/plugins/subdomain-fu/.git
Initialized empty Git repository in /Users/Tim/Code/Ruby/RainbowCube/vendor/plugins/subdomain-fu/.git/
fatal: exec index-pack failed.
fatal: index-pack failed
~/Code/Ruby/RainbowCube$ remote: Counting objects: 26, done.
remote: Compressing objects: 100% (19/19), done.
Can anyone help me??
Thanks,
Tim
glad to note that new intro is way better ;)
thanks a lot for your work, keep it up
My lame ISP (dreamhost) won't let me install gems.
I am trying to use this technique to update 3 separate classes, as opposed to 2 with a parent>child>grandchild relationship.
account has_many groups
group has_many users
Building the form is pretty straightforward. And here is what I have for the create action in the controller:
@account = Account.new(params[:account])
@group = @account.groups.build(params[:group])
@user = @group.users.build(params[:user])
@account.save
Using this method account and group are saved by user is not. If build method is not capable of handling more than 1 level then how should i create the user ensuring the group_id is populated with the new group? Any help will be greatly appreciated.
Thanks to Greg's suggestion about including different models. helped me out.
Very complicated but I´ll try it!
Thank you.
@Rajesh,
As far as I know Daemons won't work on Windows, so you'd probably have to create a service and work through that (a much bigger problem than doing it the *nix way). I found this to give you a bit of help getting started, but really it should just tell you why it is better to use Linux or OS X for some things:
http://rubyforge.org/forum/forum.php?thread_id=14841&forum_id=320
Can someone please explain why the original code is not thread save vs. pratik's code?
@purzelrakete - I actually tried that, but I get version 0.9.7.10 instead of 0.9.9.
I am doing:
gem sources -a http://gems.github.com/
gem install starling-starling
Ryan,
I was able to start the daemon fine, changed code while($running) loop and saw the changes. But now I can't stop or restart the daemon using lib/daemons/whatever_ctl stop command. I had to force kill the process from terminal to stop the daemon.
Thanks Ryan, great tutorial. I was trying to do it with the rakismet plugin but found it confusing. Your plugin seems easier and it comes with a screencast so that's easier!
Just a question, are you doing anything with the permalink attribute on the comments? Is that needed or is it optional?
Thanks for the great webcast.
To get it to work with Rails 2.1 with REST you need to do some changes. Here is my code:
# in routes.rb
map.resources :javascripts, :collection => { :hide => :get }
# in your controller
def hide
session[:announcment_hide_time]=Time.now()
respond_to do |format|
format.js # hide.js.rjs
end
end
# in the view ( I am using HAML )
= link_to_remote
'hide messages', :update => 'messages', :url => hide_javascripts_path, :method => 'get'
GOOD LUCK!
Hi Ryan,
I get this error message wheen i try to start the Daemon on windows machine.
http://gist.github.com/14555
@ Johny: many thanks!
@Ilia you have to get it off github. grab the lastest copy of workling (0.3), the README explains all :)
Re: Starling install on windows. The problem was that there is no Windows binary yet for the latest version of eventmachine gem which is a dependency for starling. I have VC++ installed so it should compile, but anyway...I installed the previous version (which appears to be all Starling requires) and then installed Starling using --ignore-dependencies.
Now I am getting a syslog error when trying to start Starling. This is documented as being fixed in version 0.9.9 in Starling Readme, but I can't figure out how to install 0.9.9...I always get 0.9.8.
Any ideas on how to get Starling 0.9.9 installed?
for some reason .build now works. still would like an answer on my first comment post.
Hi, i am implementing this for my applicatino, and seem to be running into some problems because my page is shorter then my browser window and i am getting some negative numbers, which activate the checkScroll function when it doesnt have to be. Anybody run into this same issue? Any ideas on how to solve this? Thanks in advance.
@ Ryan Bates Jul 21, 2008 at 12:01
Quote: Instead of filling the controller up with the logic, make a custom model.
I don't agree with this statement you've made Ryan. Your rails casts are great, I really like the effort you put into the rails community, but business logic shouldn't be near the models. Imo, they are strictly for the storage and handling of data, nothing more. If you want to keep the controller free of business logic (which is awesome), custom modules.etc. I find better suit this requirement. Otherwise you're mixing the "roles" of MVC.
Keen to hear your thoughts :)
I just created a plugin called PassiveRecord that makes a lot of this stuff very easy. Check it out on Github: http://github.com/artofmission/passiverecord
Hello there and thanks for this great tutorial!
I have some question regarding automated background jobs.
I am building an application which is getting some data from the remote RSS feed every 5 minutes. Then it checks some values and makes comparison of those values with user values. If condition is true e-mail is sent to the user.
Now, i am doing this every 5 minutes via cron job and rake.
Because of environment being loaded every time i am considering using starling+workling.
Someone already asked similar question here, about how to do starling jobs in a scheduled manner, and the answer was to "do" a sleep after the job is finished for let's say 5 minutes.
I am not a very good programmer nor specialist, but i doubt sleeping for 5 minutes or triggering action every 5 minutes is the same.
When i trigger the an action via cron it will allways be triggered at same time (0m, 5m, 10m etc...), however the job done with sleep will be allways run at different times, depending on how long it took it to run (0m, 5m20s, etc...), which is completely out of option for me :)
Please, correct if i got this wrong.
So, another solution i am thinking about is to create starling job which would be triggered with a cron job which would call a script with simulated http trigger of action (like when you click on deliver e-mail in your screencast).
As i said before i am not a specialist so my question is wether this is a stupid solution or what could be best.
Thanks
Im trying to update Proyect-Users-role taking this approach. But i have an ActiveRecord::ReadOnlyRecord message. My assiciation table is projects_users and it has project_id, user_id, role_id as fields. How can this be done?
Works great...I had to do the format.rss { render :layout => false }
Also, the feed doesn't validate 100%:
http://validator.w3.org/feed/docs/warning/MissingAtomSelfLink.html
I could not figure out how to generate:
<atom:link ... >
xml tag.
Ryan "...I do plan to address dynamically scheduled jobs in the next episode" - check out Rufus, superb :-)
http://rufus.rubyforge.org/rufus-scheduler/files/README_txt.html
i've updated the README for workling. i also made the error messages much friendlier - if your starling isn't running on the correct port, workling will tell you where it's expected.
workling will now also function without the fiveruns memcache client, if you're runnign an older version of starling.
so go and grab the latest workling version and look at the README :)
I am getting the following error intalling Starling - is something else required to install on Windows?:
"gem install starling
Building native extensions. This could take a while...
ERROR: Error installing starling:
ERROR: Failed to build gem native extension.
C:/InstantRails/ruby/bin/ruby.exe extconf.rb install starling"
Hey Ryan, nice one! However it's not working under passenger here... Maybe its the way passenger processes reacts to the system call.
Any advice?
Thanks and keep up the good work!
oh, and one last thing, i needed to use create instead of build, for some reason?
i kept getting a no method found error. which was odd. using rails 2.0.2 too.
thoughts?
Curious how you got your tasks to associate to the :project_id during your setter method .build code.
I have a product model which included product_photos, where i use attachment_fu to allow for the upload of the picture to the product_photos model. I can't associate the project_id in the setter method, and it isn't added during the .save method in create.
All that to say, ryanb, how did you save the project_id to each of the tasks? if you didn't how in god's name do you display three tasks to one project, if they aren't assoicated via the project_id field in the task model?
your help is always appreciate.
Hi, thx for the great tutorial, but i have some problems for with the request parameters the view sending to the controller:
i have a "voting" model which has a has_many "voting_timeslots". when saving the voting with one voting_timeslot it works great but adding more voting_timeslot i get "undefined method `vote_timeslotes=' for #<Voting:0x62c418c>" .
This is i think because of the request parameter sended to the controller, the hash isn't sorted:
{"voting"=>{"vote_timeslots"=>[{"time"=>"3",
"day"=>"2008-10-22"},
{"day"=>"2008-10-22"}],
"title"=>"f",
"description"=>"f",
"deadline"=>"October 10,
2008 12:23 AM",
"vote_timeslotes"=>[{"time"=>"3"}],
"location"=>"f"},
"commit"=>"Create Voting",
"authenticity_token"=>"f1d7720b3d68672e20948265a12af397ae6a6097"}
Here i send two voting_timeslots with the voting but they get splitted up by the other voting attributes.
I would be very greatful for every help