Permalink
Browse files

Log all the things

  • Loading branch information...
rwdaigle committed Oct 5, 2012
1 parent 0a0a9f7 commit cf5d3e9672864b97578cb36269bf5c0da4c0f1fa
Showing with 45 additions and 14 deletions.
  1. +12 −3 app/models/gist.rb
  2. +17 −9 app/models/gist_fetcher.rb
  3. +8 −1 app/models/gist_file.rb
  4. +8 −1 app/models/user.rb
View
@@ -34,10 +34,13 @@ def import(gh_gist)
}
if(existing_gist = where(gh_id: gh_id).first)
+ log({ns: self, fn: __method__}, user, existing_gist)
existing_gist.update_attributes(attributes)
existing_gist
else
- create(attributes)
+ new_gist = create(attributes)
+ log({ns: self, fn: __method__}, user, new_gist)
+ new_gist
end
end
@@ -52,11 +55,17 @@ def search(q)
end
def reindex
- find_each { |gist| gist.update_index }
- tire.index.refresh
+ log({ns: self, fn: __method__}) do
+ find_each { |gist| gist.update_index }
+ tire.index.refresh
+ end
end
end
+ def to_log
+ { gist_id: id, gist_gh_id: gh_id, gist_description: description }
+ end
+
# Required for Tire/Elasticsearch
def to_indexed_json
indexed_attributes.to_json
View
@@ -4,30 +4,38 @@ class << self
def fetch(user_id)
user = User.find(user_id)
- gh = gh_client(user)
- fetch_gists(gh, user)
- fetch_files(gh, user)
- update_search_indices(user)
+ log({ns: self, fn: __method__}, user) do
+ gh = gh_client(user)
+ fetch_gists(gh, user)
+ fetch_files(gh, user)
+ update_search_indices(user)
+ end
end
protected
# Make sure have all gist stubs imported
def fetch_gists(gh, user)
- gh.gists.each do |gh_gist|
- Gist.import(gh_gist)
+ log({ns: self, fn: __method__}, user) do
+ gh.gists.each do |gh_gist|
+ Gist.import(gh_gist)
+ end
end
end
# Fetch individual gists from API to get file contents
def fetch_files(gh, user)
- user.gists.pluck(:gh_id).each do |gh_gist_id|
- GistFile.import(gh.gist(gh_gist_id))
+ log({ns: self, fn: __method__}, user) do
+ user.gists.pluck(:gh_id).each do |gh_gist_id|
+ GistFile.import(gh.gist(gh_gist_id))
+ end
end
end
def update_search_indices(user)
- user.gists.each { |gist| gist.update_index }
+ log({ns: self, fn: __method__}, user) do
+ user.gists.each { |gist| gist.update_index }
+ end
end
private
View
@@ -19,15 +19,22 @@ def import(gh_gist)
}
if(existing_file = where(gist_id: gist.id, filename: gh_file.filename).first)
+ log({ns: self, fn: __method__}, gist, existing_file)
existing_file.update_attributes(attributes)
existing_file
else
- create(attributes)
+ new_file = create(attributes)
+ log({ns: self, fn: __method__}, gist, new_file)
+ new_file
end
end
end
end
+ def to_log
+ { file_id: id, file_filename: filename }
+ end
+
def indexed_attributes
{
filename: filename,
View
@@ -14,11 +14,18 @@ def authenticate(auth)
}
if(existing_user = User.where(gh_id: auth.uid).first)
+ log({ns: self, fn: __method__}, existing_user)
existing_user.update_attributes(attributes)
existing_user
else
- User.create(attributes)
+ new_user = User.create(attributes)
+ log({ns: self, fn: __method__}, new_user)
+ new_user
end
end
end
+
+ def to_log
+ { user: gh_username, user_id: id, user_email: gh_email }
+ end
end

0 comments on commit cf5d3e9

Please sign in to comment.