Skip to content

Commit

Permalink
Working on converted leads.
Browse files Browse the repository at this point in the history
  • Loading branch information
treeder committed Mar 24, 2012
1 parent 2389d8b commit 7ee4461
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 5 deletions.
2 changes: 2 additions & 0 deletions views/contacts.erb
Expand Up @@ -21,6 +21,7 @@
<th>Company</th>
<th>Action</th>
<th>To</th>
<th>Status</th>
<th>Salesforce ID</th>
</tr>
<% @contacts.each do |c| %>
Expand All @@ -31,6 +32,7 @@
<td><%= c.company %></td>
<td><%= c.action %></td>
<td><%= c.result %></td>
<td><%= c.status %></td>
<td><%= c.salesforce_id %></td>
</tr>
<% end %>
Expand Down
63 changes: 63 additions & 0 deletions workers/converted_worker.rb
@@ -0,0 +1,63 @@
require 'iron_worker'

class ConvertedWorker < IronWorker::Base
attr_accessor :iron_project_id
attr_accessor :iron_token

attr_accessor :mongodb_uri
attr_accessor :mongodb_database

merge_gem 'iron_mq'
merge_gem 'mongoid'

merge '../models/contact'

def run
mq = IronMQ::Client.new('token' => @iron_token, 'project_id' => @iron_project_id)
mq.queue_name = 'converted'

Mongoid.configure do |config|
config.master = Mongo::Connection.from_uri(@mongodb_uri + '/' + @mongodb_database)[@mongodb_database]
end

while true
msg = mq.messages.get
if msg.nil?
puts 'No more messages'
break
end

p msg
p msg.body
if msg.body.nil? || msg.body == ""
puts "Body is null, deleting."
msg.delete
next
end

body = JSON.parse(msg.body)

salesforce_id = body['salesforce_id']
puts "got salesforce_id #{salesforce_id}"

c = nil
begin
c = Contact.where(salesforce_id: salesforce_id).first
rescue => ex
puts "Error finding contact! #{ex.message}"
end
if c.nil?
puts "Couldn't find contact! #{salesforce_id}"
# p msg.delete
next
end
c.action = body['action']
c.status = body['to'] # opportunity
c.save!

puts "set salesforce_id for contact id #{c.id} email #{c.email}"

#p msg.delete
end
end
end
@@ -1,6 +1,6 @@
require 'iron_worker'

class SalesforcePollCreatedWorker < IronWorker::Base
class LeadWorker < IronWorker::Base
attr_accessor :iron_project_id
attr_accessor :iron_token

Expand Down
@@ -1,7 +1,7 @@
require 'iron_worker'
require 'time'
require_relative '../config'
require_relative 'salesforce_poll_created_worker'
require_relative 'converted_worker'

IronWorker.logger.level = Logger::DEBUG

Expand All @@ -10,13 +10,13 @@
iwc.project_id = @config["iron"]["project_id"]
end

worker = SalesforcePollCreatedWorker.new
worker = ConvertedWorker.new
worker.iron_project_id = @config['iron']['project_id']
worker.iron_token = @config['iron']['token']
worker.mongodb_uri = @config['mongo']['uri']
worker.mongodb_database = @config['mongo']['database']

#worker.run_local
worker.queue
worker.run_local
#worker.queue
#worker.upload
#worker.schedule(:start_at=>Time.now.iso8601, :run_every=>600)
22 changes: 22 additions & 0 deletions workers/schedule_lead_worker.rb
@@ -0,0 +1,22 @@
require 'iron_worker'
require 'time'
require_relative '../config'
require_relative 'lead_worker'

IronWorker.logger.level = Logger::DEBUG

IronWorker.configure do |iwc|
iwc.token = @config["iron"]["token"]
iwc.project_id = @config["iron"]["project_id"]
end

worker = LeadWorker.new
worker.iron_project_id = @config['iron']['project_id']
worker.iron_token = @config['iron']['token']
worker.mongodb_uri = @config['mongo']['uri']
worker.mongodb_database = @config['mongo']['database']

worker.run_local
#worker.queue
#worker.upload
#worker.schedule(:start_at=>Time.now.iso8601, :run_every=>600)

0 comments on commit 7ee4461

Please sign in to comment.