Last active
October 7, 2016 13:19
-
-
Save iloveitaly/102ea5dbebba8b5944efe4ac4cd793c6 to your computer and use it in GitHub Desktop.
Example of pushing a order payload to a transactional email service only when the state on the order is unique. http://github.com/nebulab/cangaroo/pulls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Mandrill | |
class OrderJob < Cangaroo::Job | |
include Rollbar::ActiveJob | |
connection :mandrill | |
path '/orders' | |
def perform? | |
type == 'orders' && | |
%w(the_store the_internet).include?(self.payload["channel"]) && | |
self.unique_state? | |
end | |
# we only want to send an email once based on if we have received this payload in the past | |
# we'll need to query the cangaroo translation log to see if any matching payloads for this order have existed before | |
def unique_state? | |
!self. | |
translation. | |
related_translations. | |
map { |t| t.request['status'] }. | |
uniq. | |
include? self.payload['status'] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment