lib/rhosync/source_sync.rb in rhosync-2.1.7 vs lib/rhosync/source_sync.rb in rhosync-2.1.10
- old
+ new
@@ -115,11 +115,11 @@
return false
end
true
end
- def _process_create(client_id,key,value,links,creates,deletes)
+ def _process_create(client,key,value,links,creates,deletes)
# Perform operation
link = @adapter.create value
# Store object-id link for the client
# If we have a link, store object in client document
# Otherwise, store object for delete on client
@@ -132,18 +132,25 @@
deletes ||= {}
deletes[key] = value
end
end
- def _process_update(client_id,key,value)
- # Add id to object hash to forward to backend call
- value['id'] = key
- # Perform operation
- @adapter.update value
+ def _process_update(client,key,value)
+ begin
+ # Add id to object hash to forward to backend call
+ value['id'] = key
+ # Perform operation
+ @adapter.update value
+ rescue Exception => e
+ # TODO: This will be slow!
+ cd = client.get_data(:cd)
+ client.put_data(:update_rollback,{key => cd[key]},true) if cd[key]
+ raise e
+ end
end
- def _process_delete(client_id,key,value,dels)
+ def _process_delete(client,key,value,dels)
value['id'] = key
# Perform operation
@adapter.delete value
dels ||= {}
dels[key] = value
@@ -165,17 +172,18 @@
# Remove object from queue
modified.delete(key)
# Call on source adapter to process individual object
case operation
when 'create'
- _process_create(client_id,key,value,links,creates,deletes)
+ _process_create(client,key,value,links,creates,deletes)
when 'update'
- _process_update(client_id,key,value)
+ _process_update(client,key,value)
when 'delete'
- _process_delete(client_id,key,value,dels)
+ _process_delete(client,key,value,dels)
end
rescue Exception => e
log "SourceAdapter raised #{operation} exception: #{e}"
+ log e.backtrace.join("\n")
errors ||= {}
errors[key] = value
errors["#{key}-error"] = {'message'=>e.message}
break
end