diff --git a/app/models/content_migration.rb b/app/models/content_migration.rb index 9d3e410ee83..336b63771f6 100644 --- a/app/models/content_migration.rb +++ b/app/models/content_migration.rb @@ -195,6 +195,7 @@ class ContentMigration < ActiveRecord::Base self.workflow_state = 'failed' message = "The migration plugin #{migration_settings['migration_type']} doesn't have a worker." migration_settings[:last_error] = message + ErrorReport.log_exception(:content_migration, $!) logger.error message self.save end @@ -240,6 +241,7 @@ class ContentMigration < ActiveRecord::Base self.workflow_state = :failed message = "#{e.to_s}: #{e.backtrace.join("\n")}" migration_settings[:last_error] = message + ErrorReport.log_exception(:content_migration, e) logger.error message self.save raise e diff --git a/lib/cc/importer/cc_worker.rb b/lib/cc/importer/cc_worker.rb index e66b5df1cce..051a800907e 100644 --- a/lib/cc/importer/cc_worker.rb +++ b/lib/cc/importer/cc_worker.rb @@ -20,30 +20,39 @@ module Canvas class CCWorker < Struct.new(:migration_id) def perform - cm = ContentMigration.find migration_id - settings = cm.migration_settings.clone - settings[:content_migration_id] = migration_id - settings[:user_id] = cm.user_id - settings[:attachment_id] = cm.attachment.id rescue nil + cm = ContentMigration.find_by_id migration_id + begin + settings = cm.migration_settings.clone + settings[:content_migration_id] = migration_id + settings[:user_id] = cm.user_id + settings[:attachment_id] = cm.attachment.id rescue nil - converter = CC::Importer::CCConverter.new(settings) - course = converter.export - export_folder_path = course[:export_folder_path] - overview_file_path = course[:overview_file_path] + converter = CC::Importer::CCConverter.new(settings) + course = converter.export + export_folder_path = course[:export_folder_path] + overview_file_path = course[:overview_file_path] - if overview_file_path - file = File.new(overview_file_path) - Canvas::MigrationWorker::upload_overview_file(file, cm) + if overview_file_path + file = File.new(overview_file_path) + Canvas::MigrationWorker::upload_overview_file(file, cm) + end + if export_folder_path + Canvas::MigrationWorker::upload_exported_data(export_folder_path, cm) + Canvas::MigrationWorker::clear_exported_data(export_folder_path) + end + + cm.migration_settings[:migration_ids_to_import] = {:copy=>{:assessment_questions=>true}} + cm.workflow_state = :exported + cm.progress = 0 + cm.save + rescue => e + report = ErrorReport.log_exception(:content_migration, e) + if cm + cm.workflow_state = :failed + cm.migration_settings[:last_error] = "ErrorReport:#{report.id}" + cm.save + end end - if export_folder_path - Canvas::MigrationWorker::upload_exported_data(export_folder_path, cm) - Canvas::MigrationWorker::clear_exported_data(export_folder_path) - end - - cm.migration_settings[:migration_ids_to_import] = {:copy=>{:assessment_questions=>true}} - cm.workflow_state = :exported - cm.progress = 0 - cm.save end def self.enqueue(content_migration) diff --git a/vendor/plugins/qti_exporter/lib/workers/qti_worker.rb b/vendor/plugins/qti_exporter/lib/workers/qti_worker.rb index 022422ad601..67f395ae6ad 100644 --- a/vendor/plugins/qti_exporter/lib/workers/qti_worker.rb +++ b/vendor/plugins/qti_exporter/lib/workers/qti_worker.rb @@ -3,34 +3,43 @@ module Canvas class QtiWorker < Struct.new(:migration_id) def perform - plugin = Canvas::Plugin.find(:qti_exporter) - unless plugin && plugin.settings[:enabled] - raise "Can't export QTI without the python converter tool installed." - end - cm = ContentMigration.find migration_id - settings = cm.migration_settings.clone - settings[:content_migration_id] = migration_id - settings[:user_id] = cm.user_id - settings[:attachment_id] = cm.attachment.id rescue nil - settings[:id_prepender] = cm.id - - exporter = Qti::QtiExporter.new(settings) - assessments = exporter.export - export_folder_path = assessments[:export_folder_path] - overview_file_path = assessments[:overview_file_path] + cm = ContentMigration.find_by_id migration_id + begin + plugin = Canvas::Plugin.find(:qti_exporter) + unless plugin && plugin.settings[:enabled] + raise "Can't export QTI without the python converter tool installed." + end + settings = cm.migration_settings.clone + settings[:content_migration_id] = migration_id + settings[:user_id] = cm.user_id + settings[:attachment_id] = cm.attachment.id rescue nil + settings[:id_prepender] = cm.id - if overview_file_path - file = File.new(overview_file_path) - Canvas::MigrationWorker::upload_overview_file(file, cm) - end - if export_folder_path - Canvas::MigrationWorker::upload_exported_data(export_folder_path, cm) - Canvas::MigrationWorker::clear_exported_data(export_folder_path) - end + exporter = Qti::QtiExporter.new(settings) + assessments = exporter.export + export_folder_path = assessments[:export_folder_path] + overview_file_path = assessments[:overview_file_path] - cm.migration_settings[:migration_ids_to_import] = {:copy=>{:assessment_questions=>true}}.merge(cm.migration_settings[:migration_ids_to_import] || {}) - cm.save - cm.import_content + if overview_file_path + file = File.new(overview_file_path) + Canvas::MigrationWorker::upload_overview_file(file, cm) + end + if export_folder_path + Canvas::MigrationWorker::upload_exported_data(export_folder_path, cm) + Canvas::MigrationWorker::clear_exported_data(export_folder_path) + end + + cm.migration_settings[:migration_ids_to_import] = {:copy=>{:assessment_questions=>true}}.merge(cm.migration_settings[:migration_ids_to_import] || {}) + cm.save + cm.import_content + rescue => e + report = ErrorReport.log_exception(:content_migration, e) + if cm + cm.workflow_state = :failed + cm.migration_settings[:last_error] = "ErrorReport:#{report.id}" + cm.save + end + end end def self.enqueue(content_migration)