Created
September 10, 2014 09:15
-
-
Save did/e686bfef86c78c4764e4 to your computer and use it in GitHub Desktop.
Instrumentation
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 refresh_conflicts(dispatch) | |
unavailables = [] | |
# 1. reset the unavailability of all the dispatched faces | |
_instrument 'dispatch_service.refresh_conflicts.reset' do | |
dispatch.faces.update_all(unavailable: false) | |
end | |
# 2. find the dispatched faces in conflict | |
dispatch.faces.each do |face| | |
_instrument 'dispatch_service.refresh_conflicts.fetch_one' do | |
if is_dispatched_face_in_conflict?(face) | |
unavailables << face.external_id | |
end | |
end | |
end | |
# 3. update them all (batch) | |
_instrument 'dispatch_service.refresh_conflicts.update' do | |
unavailables.each_slice(100) do |ids| | |
DispatchedFace.in(external_id: ids).update_all(unavailable: true) | |
end | |
end | |
unavailables.size | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment