Wolfmans Howlings

A programmers Blog about Programming solutions and a few other issues

Flash problems with periodically_call_remote

Posted by Jim Morris on Wed Oct 25 14:08:38 -0700 2006

I just ran into this little problem which kept me scratching my head for quite a while. My flash message didn't show up on the next action.

I have a status page which polls a database for status using periodically_call_remote, when the database reaches a certain state I show a button which says the process is complete go to next step.

The go to next step calls a controller action which does some processing that can take a few seconds, during that call any errors are dutifully written to flash like flash[:error]= "I got an error!" then does a redirect_to the listing page, where I expect to see the error flash at the top of the page.

This worked fine under development however under production on the production server I did not see those flash errors, so the user was like "duh what happened??".

I could see the errors logged in the production log so I knew the flash was getting set, so what was happening????

Well to cut a long story short, while the controller was processing the next action (which can take a few seconds), the periodically_call_remote can fire a few more times, this consumes the flash, so when it gets to the redirect_to page the flash no longer shows up. In development mode the timing is different so the status page does not fire again before the listing page shows up so the flash is displayed. Did I mention I hate race conditions :)

The solution is trivial, stick a flash.keep in the action that is called by the periodically_call_remote, and the flash is preserved for the redirect_to action. Problem solved!

Posted in Rails  |  Tags rails,flash,periodically_call_remote  |  no comments

Comments

(leave email »)