Skip to content

Instantly share code, notes, and snippets.

@did
Created September 10, 2014 09:15
Show Gist options
  • Save did/e686bfef86c78c4764e4 to your computer and use it in GitHub Desktop.
Save did/e686bfef86c78c4764e4 to your computer and use it in GitHub Desktop.
Instrumentation
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