开发者

Smart Background Thread Task in Ruby on Rails?

I need to perform a task every 5 seconds, but only when users are using the application.

As for now, I use cron that works every minute and activates a task that repeats itself every 5 seconds with sleeps between, for a minute. However, it works also when the application isn't being used.

Is there a gem that will do th开发者_运维问答is kind of thing?


If you're using cron, couldn't you just use things particular to the OS to get it to work? As in, use the underlying filesystem or OS, don't rely on Rails.

For example, your Rails app could touch a file whenever a user hits the site at all, which the cron job would check for existing before running its task. It could also check the ctime/mtime of the file and delete it if the file is too long out of date.

In that case, you wouldn't need a gem... just make your cron task smarter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜