Resque scheduled jobs are stuck in pending queue

1.5k views Asked by At

I'm creating a DripEmail campaign for my app and using resque scheduler to schedule the tasks.

I've sceduled a static job, which runs every day at a specific time and collect the user's list based on the drip settings and sends out an emailer to them.

This is my resque job user_follow_up.rb

class UserFollowUp
    @queue = :user_follow_up
    def self.perform
        User.each do |u|
            # Send the emailers to only those who are not converted
            if !user.is_converted and Date.today <= user.next_email
                stage(u)
            end
        end
    end 
end

This is my scheduler.yml

UserFollowUp:
  cron: "0 16 * * *"

I have 2 resque workers, one has my default set of tasks and the other for scheduler.

rake environment resque:work QUEUE=publish_story,accept_story,image_queue,Mango_mailer

and

rake environment resque:scheduler QUEUE=user_follow_up

Resque static jobs

When I open the resque admin interface, I'm able to see my static job detected in the list. I clicked the Queue Now button to test it. It properly enqueues the task to the queue, but doesn't execute. It keeps these tasks in the pending queue forever.

Jobs stuck in queue

This is my resque.rake, it's required

require 'resque/tasks'
require 'resque/scheduler/tasks'
require 'resque/scheduler/server'
require 'active_record'
require 'mongoid'
require 'action_controller/railtie'
require 'active_support/buffered_logger'


# load the Rails app all the time

    namespace :resque do
        puts 'Loading Rails environment for Resque'
        task :setup => :environment do
            # The schedule doesn't need to be stored in a YAML, it just needs to
            # be a hash.  YAML is usually the easiest.
            Resque.schedule = YAML.load_file("#{Rails.root}/config/scheduler.yml")
            Resque::Scheduler.dynamic = true
            Resque.logger.info 'Resque Scheduler Initialized!'
            Resque.before_first_fork do
                # Open the new separate log file
                logfile = File.open(File.join(Rails.root, 'log', 'resque.log'), 'a')
                # Activate file synchronization
                logfile.sync = true
                # Create a new buffered logger
                Resque.logger = ActiveSupport::BufferedLogger.new(logfile)
                Resque.logger.level = Logger::INFO
                Resque.logger.info 'Resque Logger Initialized!'
                puts 'Resque Logger Initialized!'
            end
        end
        task 'resque:pool:setup' do
            Resque::Pool.after_prefork do |job|
                Resque.redis.client.reconnect
            end
        end
    end

And this is my Gemfile

gem 'resque',  github: 'resque/resque' , branch: '1-x-stable'
gem 'resque_mailer', github: 'zapnap/resque_mailer'
gem 'resque-scheduler'

I'm not sure what is the issue here. Please help me with this fix.

0

There are 0 answers