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?
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.
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: