Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[#45]Refactor Email Example (master/slave, IronMQ, _ng, php) applied …

…some Ken's comments
  • Loading branch information...
commit f78888705fb09e94290741ad2b9cd30e42e72f98 1 parent 323b100
@rkononov rkononov authored
View
2  ruby_ng/email_worker/email_worker.rb
@@ -6,7 +6,7 @@ def init_mail(username, password, domain, provider)
puts "Selected gmail as a provider"
port = 587
address = "smtp.gmail.com"
- else #sendgrid - default
+ when 'sendgrid'
puts "Selected sendgrid as a provider"
port = 25
address = "smtp.sendgrid.net"
View
15 ruby_ng/email_worker/single_email_sender.rb
@@ -3,19 +3,24 @@
# loading config from config file
config_data = YAML.load_file '../../ruby/_config.yml'
+#also you could just create iron.json config file in your home directory and don't load anything
# Create an IronWorker client
client = IronWorkerNG::Client.new(:token => config_data['iw']['token'], :project_id => config_data['iw']['project_id'])
email = config_data['email']
+#general params
params = {:username => email['username'],
:password => email['password'],
- :domain => 'simpleworker.com',
- :from => email['from'],
- :to => [email['to'],email['to']],
- :subject => 'sample',
- :content => 'HEY ITs a body',
+ :domain => email['domain'],
:provider => 'gmail'
}
+#individual params
+params.merge!({
+ :from => email['from'],
+ :to => [email['to'],email['to']],
+ :subject => 'sample',
+ :content => 'HEY ITs a body'
+ })
#launching worker
client.tasks.create("email_worker", params)
View
16 ruby_ng/master_email_worker/master_email_worker.rb
@@ -1,19 +1,25 @@
require 'iron_mq'
require 'iron_worker_ng'
-# Create an IronWorker client
+
def queue_worker(config_data, to, subject, content)
puts "Preparing worker params"
+ # Create an IronWorker client
client = IronWorkerNG::Client.new(:token => config_data['iw']['token'], :project_id => config_data['iw']['project_id'])
email = config_data['email']
+ #global params
params = {:username => email['username'],
:password => email['password'],
:domain => email['domain'],
- :from => email['from'],
- :to => to,
- :subject => subject,
- :content => content,
:provider => email['provider']}
+ #individual params
+ params.merge!({
+ :from => email['from'],
+ :to => to,
+ :subject => subject,
+ :content => content
+ })
+
#adding iw token and project_id for IronCache if you don't use it you could remove following lines
params.merge!({:iw_token => config_data['iw']['token'],
:iw_project_id => config_data['iw']['project_id']})
Please sign in to comment.
Something went wrong with that request. Please try again.