diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 93446409f..7658e1778 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -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 diff --git a/app/models/product_build_list.rb b/app/models/product_build_list.rb index 7142d3f7f..0d2248097 100644 --- a/app/models/product_build_list.rb +++ b/app/models/product_build_list.rb @@ -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' diff --git a/lib/modules/models/file_store_clean.rb b/lib/modules/models/file_store_clean.rb new file mode 100644 index 000000000..bef23b3e0 --- /dev/null +++ b/lib/modules/models/file_store_clean.rb @@ -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