MissionMailer and step validation email background job

James Peret 10 jaren geleden
bovenliggende
commit
2949eaf9e4

+ 2 - 0
app/controllers/missions_controller.rb

@@ -148,6 +148,8 @@ class MissionsController < ApplicationController
148 148
       submission.date_validated = Time.now
149 149
       submission.save
150 150
       submission.agent_step.update(completed: true)
151
+      Resque.enqueue(SendStepValidationNotification, submission.agent_step.id)
152
+      #MissionMailer.step_validation_notification(submission.agent_step).deliver
151 153
       mission.check_for_completion
152 154
       redirect_to mission_control_path(mission)
153 155
     end

+ 12 - 0
app/mailers/mission_mailer.rb

@@ -0,0 +1,12 @@
1
+class MissionMailer < ActionMailer::Base
2
+  default from: "contact@avalanche.network"
3
+  
4
+  def step_validation_notification(step)
5
+    config = Info.first
6
+    mail :to        => step.mission_agent.user.email,
7
+         :subject   => "#{t 'step.step_validated'} - #{step.title}",
8
+         :from      => "no-reply@avalanche.network",
9
+         :from_name => "Avalanche System"
10
+  end
11
+  
12
+end

+ 1 - 1
app/mailers/user_mailer.rb

@@ -1,5 +1,5 @@
1 1
 class UserMailer < ActionMailer::Base
2
-  default from: "contact@website.com"
2
+  default from: "contact@avalanche.network"
3 3
   
4 4
   def signup_message(email)
5 5
     config = Info.first

+ 17 - 0
app/views/mission_mailer/step_validation_notification.html.erb

@@ -0,0 +1,17 @@
1
+!DOCTYPE html>
2
+<html>
3
+  <head>
4
+    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
5
+  </head>
6
+  <body>
7
+    <h1>Welcome to example.com, </h1>
8
+    <p>
9
+      You have successfully signed up to example.com,
10
+      your username is: .<br>
11
+    </p>
12
+    <p>
13
+      To login to the site, just follow this link: 
14
+    </p>
15
+    <p>Thanks for joining and have a great day!</p>
16
+  </body>
17
+</html>

+ 9 - 0
app/views/mission_mailer/step_validation_notification.text.erb

@@ -0,0 +1,9 @@
1
+Welcome to example.com, 
2
+===============================================
3
+ 
4
+You have successfully signed up to example.com,
5
+your username is: 
6
+ 
7
+To login to the site, just follow this link:
8
+ 
9
+Thanks for joining and have a great day!

+ 11 - 0
app/workers/send_step_validation_notification.rb

@@ -0,0 +1,11 @@
1
+class SendStepValidationNotification
2
+  @queue = :step_notifications 
3
+
4
+  def self.perform(step_id) 
5
+    # Get step
6
+    step = AgentStep.find(step_id)
7
+    # Send Step Validation Notification Email
8
+    MissionMailer.step_validation_notification(step).deliver
9
+  end 
10
+  
11
+end

+ 1 - 1
config/unicorn.rb

@@ -1,7 +1,7 @@
1 1
 # config/unicorn.rb
2 2
  
3 3
 # See comment by @paulelliott
4
-worker_processes 2
4
+worker_processes 3
5 5
 timeout 45
6 6
 preload_app true
7 7
  

+ 7 - 0
test/mailers/mission_mailer_test.rb

@@ -0,0 +1,7 @@
1
+require 'test_helper'
2
+
3
+class MissionMailerTest < ActionMailer::TestCase
4
+  # test "the truth" do
5
+  #   assert true
6
+  # end
7
+end