sheepwalker
sheepwalker

Reputation: 1760

Resque starts jobs, but do nothing

I'm using resque to do some (long time) job. And I have a few classes with the same mixed-in module for queuing. Class Service substitutes in tests, that's why it standalone and (maybe too much) complicated. So the story is when I call

Campaign.perform(user_id)

directly, everything works fine, but when I try to use queue:

Resque.enqueue(Campaign, user_id)

Job created, but seems like do nothing. At least, nothing saves into the database. Which is main task of Campaign class. I can see in resque-web-interface that jobs creates and finished, and finished (to fast, almost just after create) but no result.

I'm new in Resque and not really sure it calls it all (confused how to debug it).

Does anybody have similar problem? thanks for any help.

Module:

module Synchronisable
  def self.included(base)
    base.extend ClassMethods
  end

  module ClassMethods
    def perform(user_id)
      save_objects("#{self.name}::Service".constantize.get_objects(user_id))
    end

    protected

    def save_objects(objects)
      raise ArgumentError "should be implemented"
    end
  end

  class Service
    def self.get_objects(user)
      raise ArgumentError "should be implemented"
    end
  end
end

One of the classes:

class Campaign < ActiveRecord::Base
  include Synchronisable
  @queue = :app

  class << self
     protected 
       def save_objects(objects)
         #some stuff to save objects
       end

  end
  class Service
    def self.get_objects(user_id)
      #some stuff to get objects
    end
  end
end

Upvotes: 2

Views: 3466

Answers (4)

yilmazgunalp
yilmazgunalp

Reputation: 96

This is a very old question so not sure how rails folder structure was back then but I had the same problem and issue was with inheritance. Seems if you are using Resque your job classes shouldn't inherit from ApplicationJob.

so if your code was like this in (app/jobs/campaign_job.rb):

class Campaign < ApplicationJob
  @queue = :a_job_queue
  def self.perform
     #some background job
  end
end

then remove the inheritance i.e "< ApplicationJob"

Upvotes: 3

George Yacoub
George Yacoub

Reputation: 1456

Try this:

env TERM_CHILD=1 COUNT=2 "QUEUE=*" bundle exec rake resque:workers

Upvotes: 0

cicloon
cicloon

Reputation: 1099

You should run your worker like this:

nohup QUEUE=* rake resque:work & &> log/resque_worker_QUEUE.log

This will output everything you debug to "log/resque_worker_QUEUE.log" and you will be able to find out what's wrong with your Campaign class.

Upvotes: 1

d11wtq
d11wtq

Reputation: 35318

These jobs are almost certainly failing, due to an Exception. What is resque-web showing you on the Failures tab? You can also get this from the Rails console with:

Resque.info

or

Resque::Failure.all(0)

Upvotes: 1

Related Questions