Advertisement
Guest User

Untitled

a guest
May 24th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. class AcknowledgementWorker
  2. include Sneakers::Worker
  3.  
  4. from_queue "currencies.acknowledgements"
  5.  
  6. def work(message)
  7. consumer_id = message[:id]
  8. currency = Currency.find_by(uuid: message[:uuid])
  9.  
  10. if currency
  11. currency.update_attribute("consumer_#{consumer_id}", true)
  12. ack!
  13. else
  14. requeue_or_reject
  15. end
  16. end
  17.  
  18. private
  19.  
  20. def requeue_or_reject
  21. if !@countdown
  22. @countdown = 5
  23. elsif @countdown > 0
  24. @countdown =- 1
  25. requeue!
  26. else
  27. reject!
  28. end
  29. end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement