Skip to content

Instantly share code, notes, and snippets.

@iloveitaly
Last active October 7, 2016 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iloveitaly/102ea5dbebba8b5944efe4ac4cd793c6 to your computer and use it in GitHub Desktop.
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
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