Best way to monitor for completion of a Sidekiq job?

不羁岁月 提交于 2019-12-03 07:56:42

问题


I'm using a Sidekiq worker to complete some requests to Facebook after a user signs-in for the first time. Typically the task takes around 20 seconds or so.

I'd like to load some information on to the page using an ajax request as soon as the sync is completed, but am unsure as to the best way to check for the job completion with Javascript.

One possibility would be to configure the Sidekiq worker to set a cookie after the rest of the jobs are done. Then I can use a setTimeout function to keep checking for the cookie before calling the load function. But I'm unsure whether this is the best way to be doing this. Could I be using Redis instead?


回答1:


Paul, initially you have to take a look on this PubSub on Rails tutorial!

This will be your better solution for notify user when asynchronous things occur/complete in the backend.

tip: If you're using heroku, you'll have a lot of libraries with abstract this complexity for you.




回答2:


Paul, I would keep your concerns separated. I am assuming that the sidekiq worker uses some rails activerecord model to send some information to facebook. I would set a flag on that model to true when the facebook requests are completed successfully.

Then you can have a setTimeout on in js to poll for that change in the db... or for faster, more automatic responses you can look into using web sockets. I have used a library called Pusher in the past. It's pretty easy to integrate with rails and makes for a very snappy UI.



来源:https://stackoverflow.com/questions/16370574/best-way-to-monitor-for-completion-of-a-sidekiq-job

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!