Skip to content

Instantly share code, notes, and snippets.

@benhamill
Created October 21, 2011 03:06
Show Gist options
  • Save benhamill/1303013 to your computer and use it in GitHub Desktop.
Save benhamill/1303013 to your computer and use it in GitHub Desktop.
def train!
start_training!
find_matching_messages or return fail_training("Found no matching messages in database")
messages_with_bodies = fetch_message_bodies(found_messages) or return fail_training("Unable to fetch any bodies for matching messages")
update_tags(messages_with_bodies) or return cancel_training("Failed to update tags with new message data")
finish
end
private
def fail_training(message)
fail_training!
update_attribute(:training_summary, message)
return false
end
def cancel_training(message)
cancel_training!
Rails.logger.info("Failed to update tags with new message data")
return false
end
def train!
start_training!
found_messages = find_matching_messages
if found_messages.empty?
fail_training!
update_attribute(:training_summary, "Found no matching messages in database")
return false
end
messages_with_bodies = fetch_message_bodies(found_messages)
if messages_with_bodies.empty?
fail_training!
update_attribute(:training_summary, "Unable to fetch any bodies for matching messages")
return false
end
update_successful = update_tags(messages_with_bodies)
unless update_successful
cancel_training!
Rails.logger.info("Failed to update tags with new message data")
return false
end
finish
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment