DGuimar
DGuimar

Reputation: 35

Rufus Scheduler not running when rails server runs as daemon

I have a a rails app that is using Rufus Scheduler. When I turn on the rails server with:

rails s --port=4000

Rufus scheduler runs its tasks. If I run the rails server with:

rails s --port=4000 --daemon

Rufus no longer does its tasks. I added a couple of log messages. Here is the schedule code:

class AtTaskScheduler

  def self.start
    scheduler = Rufus::Scheduler.new

    p "Starting Attask scheduler"

    scheduler.every('5m') do
      # test sending hip chat message
      issue = Issue.new
      issue.post_to_hipchat("Starting sync with AtTask","SYNC")
      p "Launching Sync"
      Issue.synchronize
    end

  end

end

Hipchat never gets the message from the scheduler and the log never gets the statement "Launching Sync".

Any ideas on what may be causing this?

Upvotes: 1

Views: 445

Answers (1)

Chris Kinniburgh
Chris Kinniburgh

Reputation: 392

There is documentation of this issue in the rufus-scheduler docs:

There is the handy rails server -d that starts a development Rails as a daemon. The annoying thing is that the scheduler as seen above is started in the main process that then gets forked and daemonized. The rufus-scheduler thread (and any other thread) gets lost, no scheduling happens.

I avoid running -d in development mode and bother about daemonizing only for production deployment.

These are two well crafted articles on process daemonization, please read them:

If anyway, you need something like rails server -d, why not try bundle exec unicorn -D instead? In my (limited) experience, it worked out of the box (well, had to add gem 'unicorn' to Gemfile first).

Upvotes: 2

Related Questions