Adapted from Ryan Bates: application_controller.rb def call_rake(task, os, options = {}) options[:rails_env] ||= Rails.env args = options.map { |n, v| "#{n.to_s.upcase}=''#{v}''" } system "/usr/bin/rake #{task} #{args.join('' '')} --trace 2>&1 >> #{Rails.root}/log/rake.log &" if os == ''linux'' system "START rake.bat #{task} #{args.join('' '')} --trace" if os =''windows'' end special_raketasks_controller.rb def rake_espn_results Rails.env == ''development'' ? (call_rake :espn_results, ''windows'') : (call_rake :espn_results, ''linux'') flash[:notice] = "ESPN Results/Schedules running." redirect_to raketasks_url end In my view I click the manual rake task and if the rails environment is in development it opens up a dos window (I develop on windows) and runs the task so I can view it. If it''s in production then I''m on linux and it runs the task in production. What I''d like to do is change the output from posting to a log file and instead posting to a text field on the same index page. Any thoughts on what I might need to do in order to accomplish this? Thanks. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I managed to do it by using f.puts to generate the log file and then read the file using a render in the view with link_to_remote. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Okay, I wrote out some basic code to look at: http://gist.github.com/575243 This is just a basic example and here are my current issues and concerns: The view houses a link that I can click to run the example rake task. If I''m in development mode it runs in windows without opening an additional window. If I''m in production mode it runs in linux. I can click on the Read Rake Results link and it auto populated the f.puts from the rake task into a textarea partial. Issue/Concern #1: In Windows the link is clicked and the task runs in the background (no waiting or delay exists). This is what it should be doing. However, in linux, the page delays as it''s running the task. If the task is long it does not appear to run in the background so it eventually errors out, yet the task continues to run. I would like to figure out why it''s doing this. Issue/Concern #2: Locking down anyone from being able to view the page (I addressed this with my authorize method which only allows a super admin to view or run the tasks) Issue/Concern #3: I would rather have the textarea partial update using some type of observer as the file is being written. I''m unsure of what the best way to accomplish this would be. Please let me know your thoughts. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> Issue/Concern #1: In Windows the link is clicked and the task runs in > the background (no waiting or delay exists). This is what it should be > doing. However, in linux, the page delays as it''s running the task. If > the task is long it does not appear to run in the background so it > eventually errors out, yet the task continues to run.I figured out why this was happening only on my production server and not on my development one. The issue was with Phusion Passenger not having the following set: PassengerUseGlobalQueue on Without the global queue on, it couldn''t process long running background tasks. Now that it''s set, issue/concern #1 is fixed. So, I''m now able to run all manual user run tasks fine from the view using the code I supplied above. However, I''m still trying to figure out how to have the view become updated as the background process runs. I''m thinking of different ways to implement it but none seem to feel very rails like so I''m still interested in hearing possible solutions. The current solution: Click manual user run task from view. Rake task processes in the background and writes to a log file. Click link to read results. Results are read from the log file and shown in the view. The envisioned solution: Click manual user run task from view. Rake task processes in the background. Results are updated every 10 seconds in the view. I hope that helps. My example code is located here: http://gist.github.com/575243 Thanks, -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 12 Sep 2010, at 15:47, Alpha Blue wrote:> The current solution: > > Click manual user run task from view. > Rake task processes in the background and writes to a log file. > Click link to read results. > Results are read from the log file and shown in the view. > > The envisioned solution: > > Click manual user run task from view. > Rake task processes in the background. > Results are updated every 10 seconds in the view.Pretty much the same thing, just replace your link with a periodicalExecuter and you''re basically done. Best regards Peter De Berdt -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.