Permalink
Browse files

Setup backgrounding of gist fetching

  • Loading branch information...
1 parent 3bf2374 commit 579a3789840a2f81b1602cfdf906d9d3da822d70 @rwdaigle committed Oct 2, 2012
View
@@ -7,6 +7,8 @@ gem 'pg'
gem 'omniauth'
gem 'omniauth-github'
+gem 'rack-worker'
+gem 'dalli'
gem 'octokit'
gem 'queue_classic'
View
@@ -32,6 +32,7 @@ GEM
arel (3.0.2)
builder (3.0.3)
daemons (1.1.9)
+ dalli (2.2.1)
erubis (2.7.0)
eventmachine (1.0.0)
execjs (1.4.0)
@@ -97,6 +98,8 @@ GEM
rack
rack-test (0.6.2)
rack (>= 1.0)
+ rack-worker (0.0.1.rc4)
+ json
rails (3.2.8)
actionmailer (= 3.2.8)
actionpack (= 3.2.8)
@@ -143,13 +146,15 @@ PLATFORMS
ruby
DEPENDENCIES
+ dalli
haml-rails
jquery-rails
octokit
omniauth
omniauth-github
pg
queue_classic
+ rack-worker
rails (= 3.2.8)
sass-rails (~> 3.2.3)
thin
@@ -5,17 +5,11 @@ class GistsController < ApplicationController
before_filter :force_user_login
def index
- @gists = [] #gh_client.gists
+ @gists = [] #current_user.gh_client.gists
end
def refresh
puts QC.enqueue("GistFetcher.fetch", current_user.id)
redirect_to gists_path
end
-
- protected
-
- def gh_client
- @gh_client ||= Octokit::Client.new(:login => current_user.gh_username, :oauth_token => current_user.gh_oauth_token)
- end
end
@@ -3,7 +3,10 @@ class GistFetcher
class << self
def fetch(user_id)
- puts "Fetching gists for user: #{user_id}..."
+ user = User.find(user_id)
+ user.gh_client.gists.each do |gh_gist|
+ # Create local gist
+ end
end
end
end
View
@@ -16,4 +16,9 @@ def create_from_gh_oauth(token, auth)
User.create(gh_oauth_token: token, gh_username: gh_username, gh_avatar_url: gh_avatar_url, gh_url: gh_url)
end
end
+
+ # Don't like this hear, but it's convenient for now
+ def gh_client
+ @gh_client ||= Octokit::Client.new(:login => gh_username, :oauth_token => gh_oauth_token)
+ end
end
View
@@ -62,5 +62,7 @@ class Application < Rails::Application
config.middleware.use OmniAuth::Builder do
provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'], :scope => "gist"
end
+
+ # config.middleware.use Rack::Worker # errors... :(
end
end
@@ -9,7 +9,8 @@
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
- config.serve_static_assets = false
+ config.serve_static_assets = true
+ config.static_cache_control = "public, max-age=2592000"
# Compress JavaScripts and CSS
config.assets.compress = true
@@ -41,6 +42,13 @@
# Use a different cache store in production
# config.cache_store = :mem_cache_store
+ config.cache_store = :dalli_store
+
+ config.action_dispatch.rack_cache = {
+ :metastore => Dalli::Client.new,
+ :entitystore => Dalli::Client.new,
+ :allow_reload => false
+ }
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
@@ -0,0 +1,2 @@
+Rack::Worker.cache = Dalli::Client.new(nil, {:expires_in => 300})
+Rack::Worker.queue = QC
View
@@ -1,7 +1,8 @@
Gisted::Application.routes.draw do
-
root :to => 'homes#index'
+
+ # OAuth/session management
match '/login', to: 'sessions#login', :as => :login
match '/logout', to: 'sessions#logout', :as => :logout
match '/auth/github/callback', to: 'sessions#create', :via => [:post, :get], :as => :github_auth_callback

0 comments on commit 579a378

Please sign in to comment.