Have the results from that action be propagated back to the controller using a callback.
Store the result in an in memory session store.
Have the result in session be used and available from that point onward.
Controller receives the results in the callback, as expected.
# controller callback, saves result to session
# this method is executed as expected
# session id matches the one from other controller actions
def on_counter_value_calculated(context, new_value)
@counter = new_value
session[:counter] = @counter
end
However, stored session is lost in subsequent calls.
# although the same session is targeted (same id)
# the saved value is not the same
def index
@counter = session[:counter] || 0
end
"Vanja Radovanović" <elVanja@gmail.com> wrote in post #1110347:
The idea is:
- Perform some time consuming action in background.
- Have the results from that action be propagated back to the
controller
using a callback.
- Store the result in an in memory session store.
- Have the result in session be used and available from that point
onward.
This sounds like a bad idea right out of the gate. My suggestion is to
put the whole thing out of your mind.
If you have a "time consuming action" then use one of the established
backgrounding solutions that are available:
It seems session is valid only within request cycle context and although it can be accessed, the changes are not saved, as demonstrated by the project.
Hence, your suggestion to use proven techniques is the correct one
Thanks (still glad to have found the reason for above behaviour)!
Uh, no. The whole point of "session" is persisting values across
requests from a given user-agent. And assuredly it does work. If
your example didn't, there's some other issue.
Yeah, that’s the reason I first thought about using it.
But, as the example demonstrates, when I try to adjust the session value within a callback (some calculation done in background thread triggers it) then the stored value isn’t saved.