Ruby에서 몇 초가 걸리는 계산 집중적 인 작업을 즉시 시작하는 컨트롤러 동작이 있습니다. 클라이언트가 내 서버를 폴링하고 상태 업데이트를 얻길 원합니다. 내 컨트롤러에서임시 데이터를 레일에 저장하는 위치
: check_status
는 별도의 스레드에 의해 저장되는 상태를 당길 필요가 어떻게
def complex_task
Thread.new do
loop do
one_part_of_the_computationally_intensive_task
# Note how much progress we've made, in case the client asks.
save_progress
end
end
# returns to client straightaway, but task continues in background.
end
def check_status
# Retrieve state in here.
get_progress
end
참고.
save_progress
및 get_progress
기능을 어떻게 작성합니까? 어디서 상태를 저장합니까? 이것이 클라이언트에게 전송되기 때문에 session
에 저장하는 것은 좋지 않은 것처럼 보입니다. 그러나 다른 곳에서 저장합니까?
(this question 관련,하지만 훨씬 더 일반적인. 나는 완전히 다른 답변을 기대합니다.)