Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

requeue a sweatshop job in RabbitMQ

I am working on a Rails application where customer refunds are handed to a Sweatshop worker. If a refund fails (because we cannot reach the payment processor at that time) I want to requeue the job.

class RefundWorker < Sweatshop::Worker

def process_refund(job)
  if refund
    Transaction.find(job[:transaction]).update_attributes(:status => 'completed')
  else
    sleep 3
    RefundWorker.async_process_refund(job)   # requeue the job
  end
end

Is there any better way to do this than above? I haven't found any "delay" feature in RabbitMQ, and this is the best solutions I've come up with so far. I want to avoid a busy loop while requeueing.

like image 658
Nicholas C Avatar asked Oct 15 '22 11:10

Nicholas C


2 Answers

Have you looked at things like Ruote and Minion?

Some links here: http://delicious.com/alexisrichardson/rabbitmq+work+ruby

You could also try Celery which does not speak native Ruby but does speak HTTP+JSON.

All of the above work with RabbitMQ, so may help you.

Cheers

alexis

like image 152
alexis Avatar answered Oct 18 '22 15:10

alexis


Have a timed-delivery service? You'd send the message to deliver as payload, wrapped up with a time-to-deliver, and the service would hold onto the message until the specified time had been reached. Nothing like that exists in the RabbitMQ server or any of the AMQP client libraries, as far as I'm aware, but it'd be a useful thing to have.

like image 30
Tony Garnock-Jones Avatar answered Oct 18 '22 13:10

Tony Garnock-Jones