lib/rhoconnect/jobs/bulk_data_job.rb in rhoconnect-3.1.2 vs lib/rhoconnect/jobs/bulk_data_job.rb in rhoconnect-3.2.0.beta1
- old
+ new
@@ -18,23 +18,43 @@
timer = lap_timer('create_sqlite_data_file',timer)
log "bulk_data.dbfile: #{bulk_data.dbfile}"
create_hsql_data_file(bulk_data,ts) if Rhoconnect.blackberry_bulk_sync
lap_timer('create_hsql_data_file',timer)
log "finished bulk data process"
+ #bulk_data.state = :completed
+ #bulk_data.refresh_time = Time.now.to_i + Rhoconnect.bulk_sync_poll_interval
+ else
+ raise Exception.new("No bulk data found for #{params["data_name"]}")
+ end
+ rescue Exception => e
+ bulk_data.delete if bulk_data
+ log "Bulk data job raised: #{e.message}"
+ log e.backtrace.join("\n")
+ raise e
+ end
+ end
+
+ def self.after_perform_x(*args)
+ log "BulkDataJob.after_perform_x hook called ..."
+ params = args[0] # 1st parameter is bulk data
+ begin
+ bulk_data = BulkData.load(params["data_name"]) if BulkData.is_exist?(params["data_name"])
+ if bulk_data
bulk_data.state = :completed
bulk_data.refresh_time = Time.now.to_i + Rhoconnect.bulk_sync_poll_interval
+ log "BulkDataJob.after_perform_x hook set data state to complete."
else
raise Exception.new("No bulk data found for #{params["data_name"]}")
end
rescue Exception => e
bulk_data.delete if bulk_data
- log "Bulk data job raised: #{e.message}"
+ log "Bulk data after_perform_x raised: #{e.message}"
log e.backtrace.join("\n")
raise e
end
end
-
+
def self.import_data_to_object_values(db,source)
data = source.get_data(:md)
counter = {}
db.transaction do |database|
database.prepare("insert into object_values
@@ -127,9 +147,11 @@
def self.create_sqlite_data_file(bulk_data,ts)
sources_refs = {}
schema,index,bulk_data.dbfile = get_file_args(bulk_data.name,ts)
FileUtils.mkdir_p(File.dirname(bulk_data.dbfile))
+ # TODO: remove old bulk files!
+ # FileUtils.rm Dir.glob(File.join(Rhoconnect.data_directory, "#{bulk_data.name}*"))
db = DBAdapter.instance.get_connection(bulk_data.dbfile)
db.execute_batch(File.open(schema,'r').read)
src_counter = 1
\ No newline at end of file