#281: moved concerns into lib folder
This commit is contained in:
parent
75459d1da0
commit
d317eeb413
|
@ -1,7 +1,7 @@
|
||||||
# -*- encoding : utf-8 -*-
|
# -*- encoding : utf-8 -*-
|
||||||
class BuildList < ActiveRecord::Base
|
class BuildList < ActiveRecord::Base
|
||||||
include Modules::Models::CommitAndVersion
|
include Modules::Models::CommitAndVersion
|
||||||
include FileStoreClean
|
include Modules::Models::FileStoreClean
|
||||||
include AbfWorker::ModelHelper
|
include AbfWorker::ModelHelper
|
||||||
include Modules::Observers::ActivityFeed::BuildList
|
include Modules::Observers::ActivityFeed::BuildList
|
||||||
|
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
# -*- encoding : utf-8 -*-
|
|
||||||
module FileStoreClean
|
|
||||||
extend ActiveSupport::Concern
|
|
||||||
|
|
||||||
included do
|
|
||||||
def destroy
|
|
||||||
destroy_files_from_file_store if Rails.env.production?
|
|
||||||
super
|
|
||||||
end
|
|
||||||
later :destroy, :queue => :clone_build
|
|
||||||
|
|
||||||
def sha1_of_file_store_files
|
|
||||||
raise NotImplementedError, "You should implement this method"
|
|
||||||
end
|
|
||||||
|
|
||||||
def destroy_files_from_file_store(args = sha1_of_file_store_files)
|
|
||||||
files = *args
|
|
||||||
token = User.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
|
|
||||||
|
|
||||||
def later_destroy_files_from_file_store(args)
|
|
||||||
destroy_files_from_file_store(args)
|
|
||||||
end
|
|
||||||
later :later_destroy_files_from_file_store, :queue => :clone_build
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.file_exist_on_file_store?(sha1)
|
|
||||||
begin
|
|
||||||
resp = JSON(RestClient.get "#{APP_CONFIG['file_store_url']}/api/v1/file_stores.json", :params => {:hash => sha1})
|
|
||||||
rescue # Dont care about it
|
|
||||||
resp = []
|
|
||||||
end
|
|
||||||
if resp[0].respond_to?('[]') && resp[0]['file_name'] && resp[0]['sha1_hash']
|
|
||||||
true
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
|
@ -1,45 +0,0 @@
|
||||||
module RegenerationStatus
|
|
||||||
extend ActiveSupport::Concern
|
|
||||||
|
|
||||||
READY = 0
|
|
||||||
WAITING_FOR_REGENERATION = 100
|
|
||||||
REGENERATING = 200
|
|
||||||
|
|
||||||
HUMAN_STATUSES = {
|
|
||||||
READY => :ready,
|
|
||||||
WAITING_FOR_REGENERATION => :waiting_for_regeneration,
|
|
||||||
REGENERATING => :regenerating
|
|
||||||
}
|
|
||||||
|
|
||||||
HUMAN_REGENERATION_STATUSES = {
|
|
||||||
AbfWorker::BaseObserver::COMPLETED => :completed,
|
|
||||||
AbfWorker::BaseObserver::FAILED => :failed,
|
|
||||||
AbfWorker::BaseObserver::CANCELED => :canceled
|
|
||||||
}.freeze
|
|
||||||
|
|
||||||
included do
|
|
||||||
after_update :cleanup_file_store
|
|
||||||
|
|
||||||
def sha1_of_file_store_files
|
|
||||||
files = []
|
|
||||||
files << last_regenerated_log_sha1 if last_regenerated_log_sha1.present?
|
|
||||||
files
|
|
||||||
end
|
|
||||||
|
|
||||||
def human_regeneration_status
|
|
||||||
self.class::HUMAN_REGENERATION_STATUSES[last_regenerated_status] || :no_data
|
|
||||||
end
|
|
||||||
|
|
||||||
def human_status
|
|
||||||
self.class::HUMAN_STATUSES[status] || :no_data
|
|
||||||
end
|
|
||||||
|
|
||||||
def cleanup_file_store
|
|
||||||
old_log_sha1 = last_regenerated_log_sha1_was
|
|
||||||
if old_log_sha1.present? && old_log_sha1 != last_regenerated_log_sha1
|
|
||||||
later_destroy_files_from_file_store([old_log_sha1])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- encoding : utf-8 -*-
|
# -*- encoding : utf-8 -*-
|
||||||
class Platform < ActiveRecord::Base
|
class Platform < ActiveRecord::Base
|
||||||
include FileStoreClean
|
include Modules::Models::FileStoreClean
|
||||||
include RegenerationStatus
|
include Modules::Models::RegenerationStatus
|
||||||
|
|
||||||
VISIBILITIES = %w(open hidden)
|
VISIBILITIES = %w(open hidden)
|
||||||
NAME_PATTERN = /[\w\-\.]+/
|
NAME_PATTERN = /[\w\-\.]+/
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
class ProductBuildList < ActiveRecord::Base
|
class ProductBuildList < ActiveRecord::Base
|
||||||
include Modules::Models::CommitAndVersion
|
include Modules::Models::CommitAndVersion
|
||||||
include Modules::Models::TimeLiving
|
include Modules::Models::TimeLiving
|
||||||
include FileStoreClean
|
include Modules::Models::FileStoreClean
|
||||||
include AbfWorker::ModelHelper
|
include AbfWorker::ModelHelper
|
||||||
delegate :url_helpers, to: 'Rails.application.routes'
|
delegate :url_helpers, to: 'Rails.application.routes'
|
||||||
|
|
||||||
|
|
|
@ -215,11 +215,11 @@ class Project < ActiveRecord::Base
|
||||||
format_id = ProjectTag::FORMATS["#{tag_file_format(format)}"]
|
format_id = ProjectTag::FORMATS["#{tag_file_format(format)}"]
|
||||||
project_tag = project_tags.where(:tag_name => tag.name, :format_id => format_id).first
|
project_tag = project_tags.where(:tag_name => tag.name, :format_id => format_id).first
|
||||||
|
|
||||||
return project_tag.sha1 if project_tag && project_tag.commit_id == tag.commit.id && FileStoreClean.file_exist_on_file_store?(project_tag.sha1)
|
return project_tag.sha1 if project_tag && project_tag.commit_id == tag.commit.id && Modules::Models::FileStoreClean.file_exist_on_file_store?(project_tag.sha1)
|
||||||
|
|
||||||
archive = archive_by_treeish_and_format tag.name, format
|
archive = archive_by_treeish_and_format tag.name, format
|
||||||
sha1 = Digest::SHA1.file(archive[:path]).hexdigest
|
sha1 = Digest::SHA1.file(archive[:path]).hexdigest
|
||||||
unless FileStoreClean.file_exist_on_file_store? sha1
|
unless Modules::Models::FileStoreClean.file_exist_on_file_store? sha1
|
||||||
token = User.find_by_uname('rosa_system').authentication_token
|
token = User.find_by_uname('rosa_system').authentication_token
|
||||||
begin
|
begin
|
||||||
resp = JSON `curl --user #{token}: -POST -F 'file_store[file]=@#{archive[:path]};filename=#{name}-#{tag.name}.#{tag_file_format(format)}' #{APP_CONFIG['file_store_url']}/api/v1/upload`
|
resp = JSON `curl --user #{token}: -POST -F 'file_store[file]=@#{archive[:path]};filename=#{name}-#{tag.name}.#{tag_file_format(format)}' #{APP_CONFIG['file_store_url']}/api/v1/upload`
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- encoding : utf-8 -*-
|
# -*- encoding : utf-8 -*-
|
||||||
class ProjectTag < ActiveRecord::Base
|
class ProjectTag < ActiveRecord::Base
|
||||||
include FileStoreClean
|
include Modules::Models::FileStoreClean
|
||||||
|
|
||||||
FORMATS = {
|
FORMATS = {
|
||||||
'zip' => 0,
|
'zip' => 0,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class RepositoryStatus < ActiveRecord::Base
|
class RepositoryStatus < ActiveRecord::Base
|
||||||
include FileStoreClean
|
include Modules::Models::FileStoreClean
|
||||||
include RegenerationStatus
|
include Modules::Models::RegenerationStatus
|
||||||
|
|
||||||
WAITING_FOR_RESIGN = 300
|
WAITING_FOR_RESIGN = 300
|
||||||
PUBLISH = 400
|
PUBLISH = 400
|
||||||
|
|
|
@ -28,7 +28,6 @@ module Rosa
|
||||||
# Custom directories with classes and modules you want to be autoloadable.
|
# Custom directories with classes and modules you want to be autoloadable.
|
||||||
# config.autoload_paths += %W(#{config.root}/extras)
|
# config.autoload_paths += %W(#{config.root}/extras)
|
||||||
config.autoload_paths += %W(#{config.root}/app/presenters)
|
config.autoload_paths += %W(#{config.root}/app/presenters)
|
||||||
config.autoload_paths += %W(#{config.root}/app/models/concerns)
|
|
||||||
|
|
||||||
# Only load the plugins named here, in the order given (default is alphabetical).
|
# Only load the plugins named here, in the order given (default is alphabetical).
|
||||||
# :all can be used as a placeholder for all plugins not explicitly named.
|
# :all can be used as a placeholder for all plugins not explicitly named.
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
# -*- encoding : utf-8 -*-
|
||||||
|
module Modules
|
||||||
|
module Models
|
||||||
|
module FileStoreClean
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
def destroy
|
||||||
|
destroy_files_from_file_store if Rails.env.production?
|
||||||
|
super
|
||||||
|
end
|
||||||
|
later :destroy, :queue => :clone_build
|
||||||
|
|
||||||
|
def sha1_of_file_store_files
|
||||||
|
raise NotImplementedError, "You should implement this method"
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy_files_from_file_store(args = sha1_of_file_store_files)
|
||||||
|
files = *args
|
||||||
|
token = User.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
|
||||||
|
|
||||||
|
def later_destroy_files_from_file_store(args)
|
||||||
|
destroy_files_from_file_store(args)
|
||||||
|
end
|
||||||
|
later :later_destroy_files_from_file_store, :queue => :clone_build
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.file_exist_on_file_store?(sha1)
|
||||||
|
begin
|
||||||
|
resp = JSON(RestClient.get "#{APP_CONFIG['file_store_url']}/api/v1/file_stores.json", :params => {:hash => sha1})
|
||||||
|
rescue # Dont care about it
|
||||||
|
resp = []
|
||||||
|
end
|
||||||
|
if resp[0].respond_to?('[]') && resp[0]['file_name'] && resp[0]['sha1_hash']
|
||||||
|
true
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,49 @@
|
||||||
|
# -*- encoding : utf-8 -*-
|
||||||
|
module Modules
|
||||||
|
module Models
|
||||||
|
module RegenerationStatus
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
READY = 0
|
||||||
|
WAITING_FOR_REGENERATION = 100
|
||||||
|
REGENERATING = 200
|
||||||
|
|
||||||
|
HUMAN_STATUSES = {
|
||||||
|
READY => :ready,
|
||||||
|
WAITING_FOR_REGENERATION => :waiting_for_regeneration,
|
||||||
|
REGENERATING => :regenerating
|
||||||
|
}
|
||||||
|
|
||||||
|
HUMAN_REGENERATION_STATUSES = {
|
||||||
|
AbfWorker::BaseObserver::COMPLETED => :completed,
|
||||||
|
AbfWorker::BaseObserver::FAILED => :failed,
|
||||||
|
AbfWorker::BaseObserver::CANCELED => :canceled
|
||||||
|
}.freeze
|
||||||
|
|
||||||
|
included do
|
||||||
|
after_update :cleanup_file_store
|
||||||
|
|
||||||
|
def sha1_of_file_store_files
|
||||||
|
files = []
|
||||||
|
files << last_regenerated_log_sha1 if last_regenerated_log_sha1.present?
|
||||||
|
files
|
||||||
|
end
|
||||||
|
|
||||||
|
def human_regeneration_status
|
||||||
|
self.class::HUMAN_REGENERATION_STATUSES[last_regenerated_status] || :no_data
|
||||||
|
end
|
||||||
|
|
||||||
|
def human_status
|
||||||
|
self.class::HUMAN_STATUSES[status] || :no_data
|
||||||
|
end
|
||||||
|
|
||||||
|
def cleanup_file_store
|
||||||
|
old_log_sha1 = last_regenerated_log_sha1_was
|
||||||
|
if old_log_sha1.present? && old_log_sha1 != last_regenerated_log_sha1
|
||||||
|
later_destroy_files_from_file_store([old_log_sha1])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue