[refs #838] add cleaning file-store when destroing product build list && refactoring
This commit is contained in:
parent
eeb58ccd8e
commit
d0d43b0090
|
@ -1,6 +1,7 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class BuildList < ActiveRecord::Base
|
||||
include Modules::Models::CommitAndVersion
|
||||
include Modules::Models::FileStoreClean
|
||||
include AbfWorker::ModelHelper
|
||||
|
||||
belongs_to :project
|
||||
|
@ -390,22 +391,6 @@ class BuildList < ActiveRecord::Base
|
|||
.recent
|
||||
end
|
||||
|
||||
def destroy
|
||||
files, url = [], "#{APP_CONFIG['file_store_url']}/api/v1/file_stores"
|
||||
self.results.each {|r| files << r['sha1'] if r['sha1'].present?}
|
||||
self.packages.each {|pk| files << pk.sha1 if pk.sha1.present?}
|
||||
|
||||
files.each do |sha1|
|
||||
begin
|
||||
token = User.system.find_by_uname('file_store').authentication_token
|
||||
`curl --user #{token}: -X DELETE #{url}/#{sha1}.json`
|
||||
rescue # FIXME
|
||||
end
|
||||
end
|
||||
super
|
||||
end
|
||||
later :destroy, :queue => :clone_build
|
||||
|
||||
protected
|
||||
|
||||
def abf_worker_priority
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
class ProductBuildList < ActiveRecord::Base
|
||||
include Modules::Models::CommitAndVersion
|
||||
include Modules::Models::TimeLiving
|
||||
include Modules::Models::FileStoreClean
|
||||
include AbfWorker::ModelHelper
|
||||
delegate :url_helpers, to: 'Rails.application.routes'
|
||||
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
module Modules
|
||||
module Models
|
||||
module FileStoreClean
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
def destroy
|
||||
files, url = [], "#{APP_CONFIG['file_store_url']}/api/v1/file_stores"
|
||||
self.results.each {|r| files << r['sha1'] if r['sha1'].present?}
|
||||
if self.respond_to? :packages
|
||||
self.packages.each {|pk| files << pk.sha1 if pk.sha1.present?}
|
||||
end
|
||||
if files.count > 0
|
||||
token = User.system.find_by_uname('file_store').authentication_token
|
||||
uri = URI APP_CONFIG['file_store_url']
|
||||
Net::HTTP.start(uri.host, uri.port) do |http|
|
||||
files.each do |sha1|
|
||||
begin
|
||||
req = Net::HTTP::Delete.new("/api/v1/file_stores/#{sha1}.json")
|
||||
req.basic_auth token, ''
|
||||
http.request(req)
|
||||
rescue # Dont care about it
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
super
|
||||
end
|
||||
later :destroy, :queue => :clone_build
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue