forked from iron-io/heroku_iron_boomi_salesforce
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
92 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
2 changes: 1 addition & 1 deletion
2
workers/salesforce_poll_created_worker.rb → workers/lead_worker.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |