Skip to content

Commit

Permalink
katello - async manifest import, missing notices
Browse files Browse the repository at this point in the history
add missing notices when job fails
  • Loading branch information
Petr Chalupa committed Jun 22, 2012
1 parent 9a2ef30 commit a7c9be5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 39 deletions.
42 changes: 9 additions & 33 deletions src/app/controllers/providers_controller.rb
Expand Up @@ -66,40 +66,16 @@ def products_repos
def update_redhat_provider
if !params[:provider].blank? and params[:provider].has_key? :contents
temp_file = nil
begin
dir = "#{Rails.root}/tmp"
Dir.mkdir(dir) unless File.directory? dir
temp_file = File.new(File.join(dir, "import_#{SecureRandom.hex(10)}.zip"), 'w+', 0600)
temp_file.write params[:provider][:contents].read
temp_file.close
# force must be a string value
force_update = params[:force_import] == "1" ? "true" : "false"
@provider.import_manifest File.expand_path(temp_file.path), :force => force_update, :async => true,
:notify => true

rescue Exception => error
if error.respond_to?(:response)
display_message = parse_display_message(error.response)
elsif error.message
display_message = error.message
else
display_message = ""
end

error_texts = [
_("Subscription manifest upload for provider '%s' failed.") % @provider.name,
(_("Reason: %s") % display_message unless display_message.blank?),
(_("If you are uploading an older manifest, you can use the Force checkbox to overwrite " +
"existing data.") if force_update == "false")
].compact
dir = "#{Rails.root}/tmp"
Dir.mkdir(dir) unless File.directory? dir
temp_file = File.new(File.join(dir, "import_#{SecureRandom.hex(10)}.zip"), 'w+', 0600)
temp_file.write params[:provider][:contents].read
temp_file.close
# force must be a string value
force_update = params[:force_import] == "1" ? "true" : "false"
@provider.import_manifest File.expand_path(temp_file.path),
:force => force_update, :async => true, :notify => true

notice error_texts.join('<br />'), {:level => :error, :details => pp_exception(error)}

Rails.logger.error "error uploading subscriptions."
Rails.logger.error error
Rails.logger.error error.backtrace.join("\n")
# Fall-through even on error so that the import history is refreshed
end
redhat_provider
else
# user didn't provide a manifest to upload
Expand Down
36 changes: 31 additions & 5 deletions src/app/models/glue/provider.rb
Expand Up @@ -177,22 +177,48 @@ def queue_import_manifest zip_file_path, options
:priority => 3, :action => [self, :owner_import, zip_file_path, options])
pre_queue.create(:name => "import of products in manifest #{zip_file_path}",
:priority => 5, :action => [self, :import_products_from_cp])
self.save

rescue => error
if error.respond_to?(:response)
display_message = error.response # fix add parse displayMessage
elsif error.message
display_message = error.message
else
display_message = ""
end

self.task_status = nil
self.save!
if options[:notify]
error_texts = [
_("Subscription manifest upload for provider '%s' failed.") % self.name,
(_("Reason: %s") % display_message unless display_message.blank?),
(_("If you are uploading an older manifest, you can use the Force checkbox to overwrite " +
"existing data.") if options[:force] == 'false')
].compact

notice error_texts.join('<br />'), :level => :error, :details => error.backtrace.join("\n"),
:synchronous_request => false, :request_type => 'providers__update_redhat_provider'
end

Rails.logger.error "error uploading subscriptions."
Rails.logger.error error
Rails.logger.error error.backtrace.join("\n")
raise error
else
if options[:notify]
message = if AppConfig.katello?
_("Subscription manifest uploaded successfully for provider '%s'. " +
"Please enable the repositories you want to sync by selecting 'Enable Repositories' and " +
"selecting individual repositories to be enabled.")
"Please enable the repositories you want to sync by selecting 'Enable Repositories' and " +
"selecting individual repositories to be enabled.")
else
_("Subscription manifest uploaded successfully for provider '%s'.")
end
notice message % self.name,
:synchronous_request => false, :request_type => 'providers__update_redhat_provider'
end
return true
ensure
self.task_status = nil
self.save!
end

def import_products_from_cp
Expand Down
3 changes: 2 additions & 1 deletion src/config/initializers/delayed_job.rb
Expand Up @@ -4,7 +4,8 @@
# When running under Rails last caller is "/usr/share/katello/config.ru:1" but when running standalone
# last caller is "script/delayed_job:3".

if caller.last =~ /script\/delayed_job:\d+$/ || (caller.last =~ /\/rake/ && ARGV.include?("jobs:work"))
if caller.last =~ /script\/delayed_job:\d+$/ ||
(caller[-10..-1].any? {|l| l =~ /\/rake/} && ARGV.include?("jobs:work"))
level = (ENV['KATELLO_LOGGING'] || "warn").dup
level_sql = (ENV['KATELLO_LOGGING_SQL'] || "fatal").dup
Delayed::Worker.logger = KatelloLogger.new("#{Rails.root}/log/#{Rails.env}_delayed_jobs.log", level)
Expand Down

0 comments on commit a7c9be5

Please sign in to comment.