lib/rhosync/source_sync.rb in rhosync-2.1.0.beta.2 vs lib/rhosync/source_sync.rb in rhosync-2.1.0
- old
+ new
@@ -20,37 +20,10 @@
def delete(client_id)
_measure_and_process_cud('delete',client_id)
end
- # Pass through CUD to adapter, no data stored
- def pass_through_cud(cud_params,query_params)
- res,processed_objects = {},[]
- begin
- ['create','update','delete'].each do |op|
- key,objects = op,cud_params[op]
- objects.each do |key,value|
- case op
- when 'create'
- @adapter.send(op.to_sym,value)
- when 'update'
- value['id'] = key
- @adapter.send(op.to_sym,value)
- when 'delete'
- @adapter.send(op.to_sym,key)
- end
- process_objects << key
- end if objects
- end
- rescue Exception => e
- log "Error in #{op} pass through method: #{e.message}"
- res['error'] = { 'operation' => op, 'message' => e.message }
- end
- res['processed'] = process_objects
- res.to_json
- end
-
# Read Operation; params are query arguments
def read(client_id=nil,params=nil)
_read('query',client_id,params)
end
@@ -84,19 +57,17 @@
do_query(params)
end
end
def do_query(params=nil)
- result = nil
@source.if_need_refresh do
Stats::Record.update("source:query:#{@source.name}") do
return if _auth_op('login') == false
- result = self.read(nil,params)
+ self.read(nil,params)
_auth_op('logoff')
end
end
- result
end
# Enqueue a job for the source based on job type
def async(job_type,queue_name,client_id=nil,params=nil)
SourceJob.queue = queue_name
@@ -250,24 +221,23 @@
end
# Read Operation; params are query arguments
def _read(operation,client_id,params=nil)
errordoc = nil
- result = nil
begin
if operation == 'search'
client = Client.load(client_id,{:source_name => @source.name})
errordoc = client.docname(:search_errors)
compute_token(client.docname(:search_token))
- result = @adapter.search(params)
+ @adapter.search(params)
@adapter.save(client.docname(:search))
else
errordoc = @source.docname(:errors)
[:metadata,:schema].each do |method|
_get_data(method)
end
- result = @adapter.do_query(params)
+ @adapter.do_query(params)
end
# operation,sync succeeded, remove errors
Store.lock(errordoc) do
Store.flash_data(errordoc)
end
@@ -276,9 +246,9 @@
log "SourceAdapter raised #{operation} exception: #{e}"
Store.lock(errordoc) do
Store.put_data(errordoc,{"#{operation}-error"=>{'message'=>e.message}},true)
end
end
- result
+ true
end
end
end