ruby-on-railsrubyresqueresque-schedulerresque-status

How to run a resque job in the console?


I am trying to call a job in the console but always get errors.

Followed the following documentation:

Created the following file: (lib/jobs/archive_survey_jobs.rb)

module Jobs
  class ArchiveSurveysJob < ActiveJob::Base
    @queue = :setup

    def perform(survey_type)
      if SurveyTypes.all_classes.map(&:to_s).include?(survey_type)

        surveys = Survey.where(something: 'stuff')\
                        .where.not(something: 'stuff',
                                   something: 'stuff')

        surveys.each do |survey|
          do_something
        end
      end
    end
  end
end

I understand that I can do something like Resque.enqueue(ArchiveSurveysJob, 'string_here')

How can I call this in the console? If I try: Jobs::ArchiveSurveysJob.create(survey_type: 'string_here'), when I check the Resque Statuses it resulted in an error: `The task failed because of an error:

undefined local variable or method `args' for #

If I try this:

Jobs::ArchiveSurveysJob.perform(`string_here`)

Or:

Jobs::ArchiveSurveysJob.perform_now('string_here')

I get:

ArgumentError: wrong number of arguments (given 0, expected 1..2)

Please let me know if I am missing some documentation or if I am doing something wrong.


Solution

  • How I managed to do this was by creating a Rake task and calling the Job there.