Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
treeder committed Jan 13, 2012
2 parents b4390ad + e5d2ba3 commit bc3a21e
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions workers/salesforce_poll_created_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'mongoid'

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

attr_accessor :mongodb_connection
attr_accessor :mongodb_database

merge_gem 'iron_mq'

merge '../models/salesforce'

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

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

while true
msg = mq.messages.get
break if msg.nil?

msg = JSON.parse(msg)

sf = Salesforce.find(msg['id'])
sf.salesforce_id = msg['salesforce_id']
sf.save

msg.delete
end
end
end

0 comments on commit bc3a21e

Please sign in to comment.