create error reports for migration exceptions

closes #4546

Change-Id: Ie39c96e9a9617206379e008e2e779d823ca557bc
Reviewed-on: https://gerrit.instructure.com/3871
Reviewed-by: Cody Cutrer <cody@instructure.com>
Tested-by: Hudson <hudson@instructure.com>
This commit is contained in:
Bracken Mosbacker 2011-05-25 16:26:31 -06:00
parent 0d8b4fce33
commit c825cc9fc3
3 changed files with 67 additions and 47 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)