32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'app/models/apidae/export.rb', line 32
def import_data
success = true
begin
open(file_url) do |f|
begin
logger.info "Starting file import for export #{id} - project #{project_id}"
FileImport.import(f, project_id)
unless confirm_url.blank?
uri = URI(confirm_url)
req = Net::HTTP::Post.new(uri)
Net::HTTP.start(uri.hostname, uri.port) do |http|
http.request(req)
end
logger.info "Posted file import callback for export #{id} - project #{project_id}"
end
update(status: Export::COMPLETE)
if Rails.application.config.respond_to?(:apidae_import_callback)
Rails.application.config.apidae_import_callback.call(self)
end
logger.info "Completed file import for export #{id} - project #{project_id}"
rescue Exception => ex
logger.error("Failed to import export file : #{file_url}")
logger.error("Error is : #{ex} \n#{ex.backtrace.join("\n") unless ex.backtrace.blank?}")
success = false
update(status: Export::CANCELLED)
end
end
rescue OpenURI::HTTPError => err
logger.error("Failed to download export file : #{file_url}")
logger.error("Error is : #{err}")
success = false
update(status: Export::CANCELLED)
rescue Exception => e
logger.error "Failed to import file : #{e.file_url}"
logger.error("Error is : #{err}")
success = false
e.update(status: Export::CANCELLED)
end
success
end
|