Revision d3c60d51
Added by Justin Sherrill over 10 years ago
app/models/katello/provider.rb | ||
---|---|---|
|
||
attr_accessible :name, :description, :organization, :provider_type, :repository_url
|
||
|
||
serialize :discovered_repos, Array
|
||
|
||
belongs_to :organization, :inverse_of => :providers, :class_name => "Organization"
|
||
belongs_to :task_status, :inverse_of => :provider
|
||
belongs_to :discovery_task, :class_name => "Katello::TaskStatus", :dependent => :destroy, :inverse_of => :provider
|
||
has_many :products, :class_name => "Katello::Product", :inverse_of => :provider, :dependent => :destroy
|
||
has_many :repositories, :through => :products
|
||
|
||
... | ... | |
return task_status
|
||
end
|
||
|
||
def discover_repos(notify = false)
|
||
fail _("Cannot discover repos for the Red Hat Provider") if self.redhat_provider?
|
||
fail _("Repository Discovery already in progress") if self.discovery_task && !self.discovery_task.finished?
|
||
fail _("Discovery URL not set.") if self.discovery_url.blank?
|
||
self.discovered_repos = []
|
||
self.discovery_task = self.async(:organization => self.organization).start_discovery_task(notify)
|
||
self.save!
|
||
end
|
||
|
||
def discovery_url=(value)
|
||
self.discovered_repos = []
|
||
write_attribute(:discovery_url, value)
|
||
end
|
||
|
||
def as_json(*args)
|
||
super.merge('organization_label' => self.organization.label)
|
||
end
|
||
... | ... | |
end
|
||
end
|
||
|
||
private
|
||
|
||
def start_discovery_task(notify = false)
|
||
task_id = AsyncOperation.current_task_id
|
||
provider_id = self.id
|
||
|
||
#Lambda to continually update the provider
|
||
found_func = lambda do |url|
|
||
provider = Katello::Provider.find(provider_id)
|
||
provider.discovered_repos << url
|
||
provider.save!
|
||
end
|
||
#Lambda to decide to continue or not
|
||
# Using the saved task_id to compare current providers
|
||
# task id
|
||
continue_func = lambda do
|
||
new_prov = Katello::Provider.find(provider_id)
|
||
if new_prov.discovery_task.nil? || new_prov.discovery_task.id != task_id
|
||
return false
|
||
end
|
||
true
|
||
end
|
||
|
||
discover = RepoDiscovery.new(self.discovery_url)
|
||
discover.run(found_func, continue_func)
|
||
|
||
rescue => e
|
||
Notify.exception _('Repos discovery failed.'), e if notify
|
||
raise e
|
||
end
|
||
end
|
||
end
|
Also available in: Unified diff
removing provider repo discovery model additions
this was causing errors with manifest import due to serialization
of discovered repos