Delaying a job not in the main job queue after the specified delay time has elapsed when using Resque-scheduler and redis

I need to run an assignment where every time an order is created it is assigned to a supplier and if the supplier does not accept the order and updates the status within the specified time, the order is automatically rejected and the reject status is updated. The problem I am having is that the job goes to the delayed queue as shown in the resque webview, but does not move to the main queue after the specified time to delay the delays.

Here's my job.

  class AutoRejectionJob < ActiveJob::Base
    queue_as :auto_rejection_queue

   def perform(*args) 
    assignment_id = args[0]
    order_assignment = Estamps::Assignment.find(assignment_id)
    if order_assignment.status_id == 1 || order_assignment.status_id == nil
      order_assignment.status_id = 3
      order_assignment.save!
    end
   end
  end         

      

In my assignment model:

class Estamps::Assignment < ActiveRecord::Base
 after_create :enqueue_check_status 

def enqueue_check_status #  
  AutoRejectionJob.set(wait: 2.minutes).perform_later(self.id)
end    
end

      

Here, when an assignment record is created, the status is usually saved as "assigned" at the time of its creation. Now, since its creation, if the user does not update the status at the specified time, the task should automatically update the status to "denied".

I tried this method too.

def enqueue_check_status 
  Resque.enqueue_at_with_queue('auto_rejection_queue', 2.minutes.from_now, 
   AutoRejectionJob, assignment_id: self.id)  
end

      

Both submit the job to the search delayed queue, but they do not execute or execute the job in the main queue.

AutoRejection job specified in slow job list

Also, the timestamp for the job does not show the jobs to be scheduled when I click on the link of all the timetables for the slowed down job

All schedules for the first task in the pending list

I've been stuck on this issue for almost two weeks. Please help! If you need more information, let me know. Having a hard time with this.

+3


source to share


1 answer


I have solved this problem.

Most of the time, having working workers is not enough to handle slower jobs. You must complete a special rake task:

$ PIDFILE=./resque-scheduler.pid BACKGROUND=yes \
    rake resque:scheduler

      

The resque: schedlerer rake task checks scheduled jobs and pending jobs (every 5 seconds by default) and moves them for processing by your workers. You can learn more about how to set up and configure the raque: scheduler rake task and its settings on the official reque-scheduler gem readme .

In my case, I used the capistrano-resque gem to deploy and manage workers (restart them when capistrano deploys a new version) by adding a line to the deploy.rb file:

after "deploy:restart", "resque:restart"

      



While this downloaded my workers (and restarted them as it should), you need to add an extra line (for deploy.rb):

after 'passenger:restart', 'resque:scheduler:restart'

      

To get the capistrano to run the resque: scheduler task for you.

After I did that, everything worked perfectly fine (and actually loaded the held jobs retrospectively that should have been processed but hadn't yet been).

As stated, however, if you have problems, make sure your rake resque: scheduler function has access to environment variables - or this won't work.

+1


source







All Articles