diff --git a/app/admin/node_instructions.rb b/app/admin/node_instructions.rb index 9b14fb554..323568935 100644 --- a/app/admin/node_instructions.rb +++ b/app/admin/node_instructions.rb @@ -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 diff --git a/app/jobs/restart_nodes_job.rb b/app/jobs/restart_nodes_job.rb index 74345f056..b0063d497 100644 --- a/app/jobs/restart_nodes_job.rb +++ b/app/jobs/restart_nodes_job.rb @@ -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 diff --git a/app/models/node_instruction.rb b/app/models/node_instruction.rb index 5daa15ee8..b720ebda4 100644 --- a/app/models/node_instruction.rb +++ b/app/models/node_instruction.rb @@ -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