mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 08:54:23 -05:00
Moved work into thread to repsond quickly
This commit is contained in:
@@ -85,43 +85,48 @@ class QboController < ApplicationController
|
|||||||
|
|
||||||
# proceed if the request is good
|
# proceed if the request is good
|
||||||
if hash.eql? signature
|
if hash.eql? signature
|
||||||
if request.headers['content-type'] == 'application/json'
|
Thread.new do
|
||||||
data = JSON.parse(data)
|
if request.headers['content-type'] == 'application/json'
|
||||||
else
|
data = JSON.parse(data)
|
||||||
# application/x-www-form-urlencoded
|
|
||||||
data = params.as_json
|
|
||||||
end
|
|
||||||
# Process the information
|
|
||||||
entities = data['eventNotifications'][0]['dataChangeEvent']['entities']
|
|
||||||
entities.each do |entity|
|
|
||||||
id = entity['id'].to_i
|
|
||||||
name = entity['name']
|
|
||||||
|
|
||||||
logger.info "Casting #{name.constantize} to obj"
|
|
||||||
|
|
||||||
# Magicly initialize the correct class
|
|
||||||
obj = name.constantize
|
|
||||||
|
|
||||||
# for merge events
|
|
||||||
obj.destroy(entity['deletedId']) if entity['deletedId']
|
|
||||||
|
|
||||||
#Check to see if we are deleting a record
|
|
||||||
if entity['operation'].eql? "Delete"
|
|
||||||
obj.destroy(id)
|
|
||||||
#if not then update!
|
|
||||||
else
|
else
|
||||||
begin
|
# application/x-www-form-urlencoded
|
||||||
obj.sync_by_id(id)
|
data = params.as_json
|
||||||
rescue => e
|
end
|
||||||
logger.error "Failed to call sync_by_id on obj"
|
# Process the information
|
||||||
logger.error e.message
|
entities = data['eventNotifications'][0]['dataChangeEvent']['entities']
|
||||||
logger.error e.backtrace.join("\n")
|
entities.each do |entity|
|
||||||
|
id = entity['id'].to_i
|
||||||
|
name = entity['name']
|
||||||
|
|
||||||
|
logger.info "Casting #{name.constantize} to obj"
|
||||||
|
|
||||||
|
# Magicly initialize the correct class
|
||||||
|
obj = name.constantize
|
||||||
|
|
||||||
|
# for merge events
|
||||||
|
obj.destroy(entity['deletedId']) if entity['deletedId']
|
||||||
|
|
||||||
|
#Check to see if we are deleting a record
|
||||||
|
if entity['operation'].eql? "Delete"
|
||||||
|
obj.destroy(id)
|
||||||
|
#if not then update!
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
obj.sync_by_id(id)
|
||||||
|
rescue => e
|
||||||
|
logger.error "Failed to call sync_by_id on obj"
|
||||||
|
logger.error e.message
|
||||||
|
logger.error e.backtrace.join("\n")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# Record that last time we updated
|
# Record that last time we updated
|
||||||
Qbo.update_time_stamp
|
Qbo.update_time_stamp
|
||||||
|
|
||||||
|
end
|
||||||
|
ActiveRecord::Base.connection.close
|
||||||
|
end
|
||||||
|
|
||||||
# The webhook doesn't require a response but let's make sure we don't send anything
|
# The webhook doesn't require a response but let's make sure we don't send anything
|
||||||
render :nothing => true, status: 200
|
render :nothing => true, status: 200
|
||||||
|
|||||||
Reference in New Issue
Block a user