I’m using resque-status for Resque/Redis…
https://github.com/quirkey/resque-status
I basically want to create a new Sinatra method .. something like below. I only have 2 JobsWithStatus so it could either return both or a specific one, i dont really care.
post '/getstatus' do
# return status here of all kinds (or specific)
end
Then I want to output the % complete via jquery on the frontend using a polling timer that checks the status every 5 seconds.
This is what I have
post '/refresh' do
job_id = PostSaver.create(:length => Forum.count)
status = Resque::Status.get(job_id)
redirect '/'
end
It says in the documentation i can just use status.pct_complete but it always returns 0? Even then, I’m new to ruby and even IF the variable showed the proper % complete, I’m not sure how to make that variable work inside of a separate sinatra entry (in /getstatus rather than /refresh).
I tried this however and it keeps returning 0
post '/refresh' do
job_id = PostSaver.create(:length => Forum.count)
status = Resque::Status.get(job_id)
sleep 20
status.pct_complete.to_s
end
Saw your question over on reddit…
To have the status come back as something other than 0, you need to use the
at(http://rubydoc.info/github/quirkey/resque-status/master/Resque/JobWithStatus:at) method to set a percentage during the calculation you’re running.You probably don’t want
sleepcalls inside an action. The timer should be in jQuery.Sharing Status
Then in whatever is getting the status (some jQuery#ajax call?), you can grab the job_id from the returned JSON and then with your next request, you might do something like: