Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8775317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:46:28+00:00 2026-06-13T18:46:28+00:00

I am trying to use Ruby’s daemon gem and loop the restart of a

  • 0

I am trying to use Ruby’s daemon gem and loop the restart of a daemon that has its own loop. My code looks like this now:

require 'daemons'

while true
  listener = Daemons.call(:force => true) do
    users = accounts.get_updated_user_list

    TweetStream::Client.new.follow(users) do |status|
      puts "#{status.text}"
    end
  end
  sleep(60)
  listener.restart
end

Running this gives me the following error (after 60 seconds):

undefined method `restart' for #<Daemons::Application:0x007fc5b29f5658> (NoMethodError)

So obviously Daemons.call doesn’t return a controllable daemon like I think it does. What do I need to do to set this up correctly. Is a daemon the right tool here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:46:29+00:00Added an answer on June 13, 2026 at 6:46 pm

    I think this is what you’re after, although I haven’t tested it.

    class RestartingUserTracker
      def initialize
        @client = TweetStream::Client.new
      end
    
      def handle_status(status)
        # do whatever it is you're going to do with the status
      end
    
      def fetch_users
        accounts.get_updated_user_list
      end
    
      def restart
        @client.stop_stream
        users = fetch_users
        @client.follow(users) do |status|
          handle_status(status)
        end
      end
    end
    
    EM.run do
      client = RestartingUserTracker.new
      client.restart
    
      EM::PeriodicTimer.new(60) do
        client.restart
      end
    end
    

    Here’s how it works:

    TweetStream uses EventMachine internally, as a way of polling the API forever and handling the responses. I can see why you might have felt stuck, because the normal TweetStream API blocks forever and doesn’t give you a way to intervene at any point. However, TweetStream does allow you to set up other things in the same event loop. In your case, a timer. I found the documentation on how to do that here: https://github.com/intridea/tweetstream#removal-of-on_interval-callback

    By starting up our own EventMachine reactor, we’re able to inject our own code into the reactor as well as use TweetStream. In this case, we’re using a simple timer that just restarts the client every 60 seconds.

    EventMachine is an implementation of something called the Reactor Pattern. If you want to fully understand and maintain this code, it would serve you well to find some resources about it and gain a full understanding. The reactor pattern is very powerful, but can be difficult to grasp at first.

    However, this code should get you started. Also, I’d consider renaming the RestartingUserTracker to something more appropriate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the google_search ruby library (code follows) but it complains that
I am trying to use a Ruby gem called shotgun that requires fork(2) command
background: trying to use the twitter gem for ruby-on-rails. in routes: map.resources :twitter_sessions map.finalize_twitter_sessions
I have been trying to use the ruby-git gem to make commits etc from
I am currently trying to use the Grackle Ruby GEM to integrate with the
Trying to use the whenever ruby gem , however (no pun intended) errors occur
I am currently trying to use the activerecord gem in Ruby but I'm quite
I have a regex, that I'm trying to use in Ruby. Here is my
I'm trying to use a Ruby gem called ice_cube in IRB, but it doesn't
In IDea 11.1.3 Build-IU#117.798 and trying to use its Ruby plugin to run specs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.