#376: refactoring according to Alexander's comments
This commit is contained in:
parent
aea5c94219
commit
16f2bbb246
|
@ -70,19 +70,19 @@ ActiveAdmin.register NodeInstruction do
|
|||
|
||||
collection_action :lock_all, method: :post do
|
||||
NodeInstruction.lock_all
|
||||
flash[:info] = 'Locked successfully'
|
||||
flash[:notice] = 'Locked successfully'
|
||||
redirect_to admin_node_instructions_path
|
||||
end
|
||||
|
||||
collection_action :unlock_all, method: :post do
|
||||
NodeInstruction.unlock_all
|
||||
flash[:info] = 'Unlocked successfully'
|
||||
flash[:notice] = 'Unlocked successfully'
|
||||
redirect_to admin_node_instructions_path
|
||||
end
|
||||
|
||||
member_action :force, method: :patch do
|
||||
resource.send(params[:state])
|
||||
flash[:info] = 'Updated successfully'
|
||||
flash[:notice] = 'Updated successfully'
|
||||
redirect_to admin_node_instruction_path(resource)
|
||||
end
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ class RestartNodesJob
|
|||
return if NodeInstruction.all_locked?
|
||||
available_nodes = RpmBuildNode.all.map{ |n| n.user_id }.compact.uniq
|
||||
NodeInstruction.where(status: NodeInstruction::READY).
|
||||
where('user_id NOT IN (?)', available_nodes).find_each(&:restart)
|
||||
where.not(user_id: available_nodes).find_each(&:restart)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -10,13 +10,17 @@ class NodeInstruction < ActiveRecord::Base
|
|||
|
||||
belongs_to :user
|
||||
|
||||
scope :duplicate, -> id, user_id {
|
||||
where.not(id: id.to_i).where(user_id: user_id, status: STATUSES - [DISABLED])
|
||||
}
|
||||
|
||||
attr_encrypted :instruction, key: APP_CONFIG['keys']['node_instruction_secret_key']
|
||||
|
||||
validates :user, presence: true
|
||||
validates :instruction, presence: true, length: { maximum: 10000 }
|
||||
validates :status, presence: true
|
||||
validate -> {
|
||||
errors.add(:status, 'Can be only single active instruction for each node') if !disabled? && NodeInstruction.where('id != ?', id.to_i).where(user_id: user_id, status: STATUSES - [DISABLED]).exists?
|
||||
errors.add(:status, 'Can be only single active instruction for each node') if !disabled? && NodeInstruction.duplicate(id.to_i, user_id).exists?
|
||||
}
|
||||
|
||||
attr_accessible :instruction, :user_id, :output, :status
|
||||
|
|
Loading…
Reference in New Issue