5

我正在开发一个 Rails 应用程序,将客户退款交给 Sweatshop 工作人员。如果退款失败(因为我们当时无法联系到付款处理器)我想重新排队工作。

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

有没有比上面更好的方法来做到这一点?我在 RabbitMQ 中没有发现任何“延迟”功能,这是迄今为止我想出的最好的解决方案。我想在重新排队时避免繁忙的循环。

4

3 回答 3

3

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

于 2010-01-05T16:39:07.310 回答
1

有定时送达服务吗?您将发送消息以作为有效负载进行交付,并以交付时间结束,并且服务将保留该消息,直到达到指定的时间。据我所知,RabbitMQ 服务器或任何 AMQP 客户端库中都不存在类似的东西,但拥有它会很有用。

于 2010-01-05T14:12:46.553 回答
0

AMQP(或至少 RabbitMQ)似乎不支持“延迟这项工作”的想法。因此,如果工作失败,则从工作人员内部重新排队同一工作的方法似乎是目前最好的解决方案。

我的代码在演示环境中工作,到目前为止它满足了我的需求。

于 2010-01-10T14:52:08.420 回答