Skip to content

Instantly share code, notes, and snippets.

@louism2
Created July 11, 2013 20:56
Show Gist options
  • Save louism2/5979178 to your computer and use it in GitHub Desktop.
Save louism2/5979178 to your computer and use it in GitHub Desktop.
def Inventory.handle_inventory_creation(inventory_list)
invalid_items = 0
retries = 2
inventory_list.each_with_index do |item, idx|
logger.debug(">>>>>>>>>>>>>>>>> inside the loop #{idx}")
i = Inventory.new(item)
i.save
i.valid? ? i.save! : i.save!(:validate => false); invalid_items+=1;
end
invalid_items
rescue StandardError => e
sleep 1
if retries > 0
retries-=1
retry
else
retries = 2
logger.error(">>>>>>>>>>>>>>>>>> save! raised an error when trying to save a new piece of inventory")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment