0

Here is my scenario: I have some data coming into serial port. I want to keep collecting this data and store in the database. Then the rails app uses this data from the database and shows some statistics like graphs and stuff.

So my question is how can I keep collecting this data in a separate thread from the rails app, while the rest of the things work like any other rails app on the database.

If there is a better way of doing this please advice.

PS: I dont have any problem in reading from serial port. This is about doing this task from rails app in separate thread.

2 Answers 2

1

Use the delayed_job gem.

Delayed_job (or DJ) encapsulates the common pattern of asynchronously executing longer tasks in the background.

Sign up to request clarification or add additional context in comments.

4 Comments

i am confused. can you please explain in a bit detail how will this help my case?
you can watch the railscast about this gem - railscasts.com/episodes/171-delayed-job or the text version - asciicasts.com/episodes/171-delayed-job
okay! i just saw the railcast and looks like thats exactly what I need. I have a couple of questions though. The send_later method in the railcast is being called in a particular method of a controller. I want my task to begin as soon as rail app starts (server starts). Also the job i am running has no connection to any controller as such, so where should i add the method to be called using send_later? and finally my job runs indefinitely, how does that affect this arrangement?
If you are using capistrano for the deployment look at this - github.com/collectiveidea/delayed_job/wiki/…. And if you want to add some jobs without connection to any controller, you can add these jobs in your config\initializers folder
1

Another thing you can check out is the resque gem which github published, it makes use of redis as a working queue, and has a very handy web interface, that helps controlling the working threads. It is very similar to delayed jobs, but may fit your needs in a better way.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.