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 6172603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:25:24+00:00 2026-05-23T23:25:24+00:00

Kinda new to Rails, so please cope with me. What i’m doing now is

  • 0

Kinda new to Rails, so please cope with me. What i’m doing now is background processing some Ruby code use Resque. To get the Rescque rake task started, I’ve been using (on heroku), I have a resque.rake file with that recommended code to attach into heroku’s magical(or strange) threading architecture:

require "resque/tasks"
require 'resque_scheduler/tasks'

task "resque:setup" => :environment do
  ENV['QUEUE'] = '*'
end


desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"

Since I need access to the Rails code, I reference :environment. If I set at least 1 worker dyno in the background on heroku, my Resque does great, gets cleared, everything is happy. Until i try to automate stuff…

So I wanted to evolve the code and automatically fill the queue with relevant tasks every minute or so. Do that (without using cron, because heroku is not adequate with cron), I declare an initializer named task_scheduler.rb that uses Rufus scheduler to run tasks:

scheduler = Rufus::Scheduler.start_new

scheduler.in '5s' do
  autoprocessor_method
end

scheduler.every '1m' do
  autoprocessor_method
end

Things appear to work awesome for a while….then the rake process just stops picking up from the queue unexplainably. The queue just gets larger and larger. Even if i have multiple worker dynos running, they all eventually get tired and stop processing the queue. I’m not sure what I am doing wrong, but I suspect the referencing of the Rails environment in my rake task is causing the task_scheduler.rb code to run again, causing duplicate scheduling. I’m wondering how to solve that problem if someone knows, and I’m also curious if that is the reason for the rake task to stop working.

Thank you

  • 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-05-23T23:25:25+00:00Added an answer on May 23, 2026 at 11:25 pm

    You should not be booting the scheduler in an initializer, you should have a daemon process running the scheduler and filling up your queue. It would be something like this (“script/scheduler”):

    #!/usr/bin/env ruby
    
    root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
    Dir.chdir(root)
    
    require 'rubygems'
    gem 'daemons'
    require 'daemons'
    
    options = {
        :dir_mode   => :normal,
        :dir        => File.join(root, 'log'),
        :log_output => true,
        :backtrace  => true,
        :multiple   => false
    }
    
    Daemons.run_proc("scheduler", options) do
    
      Dir.chdir(root)
      require(File.join(root, 'config', 'environment'))
    
      scheduler = Rufus::Scheduler.start_new
    
      scheduler.in '5s' do
        autoprocessor_method
      end
    
      scheduler.every '1m' do
        autoprocessor_method
      end
    
    end
    

    And you can call this script as a usual daemon from your app:

    script/scheduler start
    

    This is going to make sure you have only one process sending work for the resque workers instead of one for each mongrel that you’re running.

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

Sidebar

Related Questions

I am kinda new to this Regex thing. When analyzing some code I frequently
I'm kinda new to Flex. I have trying to send Hash from Ruby on
I am kinda new to database designing so i ask for some advices or
I'm kinda new to rails so forgive if this is a stupid question. The
I'm kinda new to using Rails, and an app I am working on is
I'm new to Mongo DB and Mongoid (and still kinda new to Ruby on
I am kind of new to Rails and I want to write some self.down
Please can you share your approach / methodology to debugging in Ruby / Rails.
I'm very new to Ruby on Rails, and even newer to Haml, i started
I'm kinda new to rails (3) and I stumbled upon a small... doorstep. Does

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.