Last active
August 29, 2015 14:04
-
-
Save alexstubbs/80aca27fb25a2162840c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def run | |
users_with_recent_parcels.find_each do |user| | |
begin | |
next if has_trust_pilot_email?(user) | |
schedule_trust_pilot_email_for(user) if has_recently_scanned_label?(user) | |
rescue Exception => e | |
Airbrake.notify e | |
end | |
end | |
end | |
def has_recently_scanned_label?(user) | |
parcels = Parcel.includes(:netdespatch_logs).joins(:order). | |
where("orders.paid_at" => time_range). | |
where("orders.user_id" => user.id) | |
parcels.each do |parcel| | |
begin | |
parcel_tracker = ParcelTracker.find(parcel.computed_consignment) | |
return true if parcel_tracker.events.any? && !parcel_tracker.only_booked? | |
rescue Netdespatch::NotFoundError | |
#nothing to do here, since we end up returning false anyway | |
end | |
end | |
return false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment