redis config

jamesperet 9 years ago
parent
commit
20baff3679

+ 1 - 0
Gemfile

@@ -54,6 +54,7 @@ gem "carrierwave"
54 54
 gem 'i18n'
55 55
 gem 'rails_12factor', group: :production
56 56
 gem 'gibbon'
57
+gem 'resque'
57 58
 
58 59
 group :test do
59 60
   gem "rspec"

+ 19 - 0
Gemfile.lock

@@ -153,6 +153,7 @@ GEM
153 153
       subexec (~> 0.2.1)
154 154
     mini_portile (0.6.0)
155 155
     minitest (4.7.5)
156
+    mono_logger (1.1.0)
156 157
     multi_json (1.10.1)
157 158
     multi_test (0.1.1)
158 159
     multi_xml (0.5.5)
@@ -165,6 +166,8 @@ GEM
165 166
     pg (0.17.1)
166 167
     polyglot (0.3.5)
167 168
     rack (1.5.2)
169
+    rack-protection (1.5.3)
170
+      rack
168 171
     rack-test (0.6.2)
169 172
       rack (>= 1.0)
170 173
     rails (4.0.4)
@@ -189,7 +192,16 @@ GEM
189 192
     rdoc (4.1.2)
190 193
       json (~> 1.4)
191 194
     redcarpet (3.1.2)
195
+    redis (3.1.0)
196
+    redis-namespace (1.5.1)
197
+      redis (~> 3.0, >= 3.0.4)
192 198
     ref (1.0.5)
199
+    resque (1.25.2)
200
+      mono_logger (~> 1.0)
201
+      multi_json (~> 1.0)
202
+      redis-namespace (~> 1.3)
203
+      sinatra (>= 0.9.2)
204
+      vegas (~> 0.1.2)
193 205
     rspec (3.1.0)
194 206
       rspec-core (~> 3.1.0)
195 207
       rspec-expectations (~> 3.1.0)
@@ -222,6 +234,10 @@ GEM
222 234
     simple_form (3.0.2)
223 235
       actionpack (~> 4.0)
224 236
       activemodel (~> 4.0)
237
+    sinatra (1.4.5)
238
+      rack (~> 1.4)
239
+      rack-protection (~> 1.4)
240
+      tilt (~> 1.3, >= 1.3.4)
225 241
     sprockets (2.11.0)
226 242
       hike (~> 1.2)
227 243
       multi_json (~> 1.0)
@@ -256,6 +272,8 @@ GEM
256 272
     uglifier (2.5.3)
257 273
       execjs (>= 0.3.0)
258 274
       json (>= 1.8.0)
275
+    vegas (0.1.11)
276
+      rack (>= 1.0.0)
259 277
     warden (1.2.3)
260 278
       rack (>= 1.0)
261 279
     xpath (2.0.0)
@@ -292,6 +310,7 @@ DEPENDENCIES
292 310
   rails (= 4.0.4)
293 311
   rails_12factor
294 312
   redcarpet
313
+  resque
295 314
   rspec
296 315
   rspec-rails
297 316
   sass-rails

+ 2 - 2
app/mailers/user_mailer.rb

@@ -1,9 +1,9 @@
1 1
 class UserMailer < ActionMailer::Base
2 2
   default from: "contact@website.com"
3 3
   
4
-  def signup_message(user)
4
+  def signup_message(email)
5 5
     config = Info.first
6
-    mail :to        => user.email,
6
+    mail :to        => email,
7 7
          :subject   => ("Welcome to "+ config.website_name),
8 8
          :from      => config.contact_email,
9 9
          :from_name => config.website_name,

+ 3 - 10
app/models/subscription.rb

@@ -1,7 +1,7 @@
1 1
 class Subscription < ActiveRecord::Base
2 2
   
3 3
   after_create do
4
-      subscribe_to_mailchimp
4
+    subscribe_to_mailchimp
5 5
   end
6 6
   
7 7
   def full_name
@@ -17,15 +17,8 @@ class Subscription < ActiveRecord::Base
17 17
       end
18 18
   end
19 19
   
20
-  def subscribe_to_mailchimp testing=false
21
-    return true if (Rails.env.test? && !testing)
22
-    list_id = ENV['MAILCHIMP_LIST_ID']
23
-    response = Rails.configuration.mailchimp.lists.subscribe({
24
-      id: list_id,
25
-      email: {email: email},
26
-      double_optin: false
27
-    })
28
-    #response
20
+  def subscribe_to_mailchimp
21
+    Resque.enqueue(SubscribeToMailchimp, self.id)
29 22
   end
30 23
   
31 24
 end

+ 6 - 8
app/models/user.rb

@@ -17,19 +17,17 @@ class User < ActiveRecord::Base
17 17
   end
18 18
   
19 19
   after_create do
20
-      subscribe_user
21
-      send_signup_mail
20
+      after_signup_tasks
22 21
   end
23 22
   
24
-  def subscribe_user
23
+  def after_signup_tasks
24
+    # Send signup email (worker)
25
+    Resque.enqueue(SendSignupMessage, self.id)
26
+    # Add user to subscription list
25 27
     if Subscription.find_by_email(self.email) == nil
26 28
       Subscription.create(first_name: self.first_name, last_name: self.last_name, email: self.email)
27 29
     end
28
-  end
29
-  
30
-
31
-  def send_signup_mail
32
-      UserMailer.signup_message(self).deliver 
30
+    # Mixpanel Tracking Analytics
33 31
   end
34 32
   
35 33
 end

+ 0 - 0
app/workers/send_contact_message.rb


+ 14 - 0
app/workers/send_signup_message.rb

@@ -0,0 +1,14 @@
1
+class SendSignupMessage
2
+  @queue = :send_signup_message_queue 
3
+  
4
+  def self.perform(user_id) 
5
+    
6
+    # Get User
7
+    user = User.find_by_id(user_id)
8
+    
9
+    # Send Signup Email
10
+    UserMailer.signup_message(user.email).deliver
11
+    
12
+  end 
13
+  
14
+end

+ 20 - 0
app/workers/subscribe_to_mailchimp.rb

@@ -0,0 +1,20 @@
1
+class SubscribeToMailchimp
2
+  @queue = :subscribe_to_mailchimp_queue 
3
+  
4
+  def self.perform(id) 
5
+    
6
+    # Get User
7
+    subscription = Subscription.find_by_id(id)
8
+
9
+    return true if (Rails.env.test? && !testing)
10
+    list_id = ENV['MAILCHIMP_LIST_ID']
11
+    response = Rails.configuration.mailchimp.lists.subscribe({
12
+      id: list_id,
13
+      email: {email: subscription.email},
14
+      double_optin: false
15
+    })
16
+
17
+    
18
+  end 
19
+  
20
+end

+ 2 - 0
lib/tasks/resque.rake

@@ -0,0 +1,2 @@
1
+require "resque/tasks" 
2
+task "resque:setup" => :environment