Arnauld
Arnauld

Reputation: 138

Rails 4: How to implement a frequent poll task (every 10 seconds)

folks.

I am working on a Rails 4 app that need to poll the network every 10s for some data. The peers are small embedded systems that return a time_stamp and some data I post to the DB. I am using MRI 2.0.0 + Rails 4.0.0 on Ubuntu 12.04 64-bit.

In this fashion, I created a "singleton-like" service object in my application.rb and got it to run a synched polling Thread. This poller updates my ActiveRecord models into the DB.

I learned that Threading in not recommended in Ruby/Rails. But unfortunately I could not find any other solution. This polling mechanism is critical to the app data capture routines and is eating my time.

Now I've got under two "unkowns":

1> Is there any solution for this app structure? Is Threading a viable solution? 2> As I am still in dev mode there is only one "thin" running. Will my app brake when clustering 3 "thins" behind a nginx/apache deploy?

Thanks in advance.

Upvotes: 2

Views: 743

Answers (1)

Clinton
Clinton

Reputation: 2366

Check out Resque, DelayedJob, or Sidekiq. You want to have a separate process doing background task management, so your Rails application is primarily concerned with handling web requests, and not with background work.

Upvotes: 1

Related Questions