Last active
December 28, 2022 06:39
-
-
Save verlihirsh/4f0a6bd3dd6164b9217174beea5a0cab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Agents < ActiveRecord::Base | |
| has_many :operations | |
| attr_accessor :all_operations_are_success | |
| def operators | |
| self.operations.map { |o| o.operator } | |
| end | |
| def prepare_agent_for_operation | |
| self.operations.where(status: 'preparing').each do |operation| | |
| operation.weapons.each do |weapon| | |
| weapon.update(status: 'ready') | |
| end | |
| end | |
| self.operations.map do |o| | |
| o.weapons.map do |w| | |
| w.status == 'ready' | |
| end | |
| o.update(status: 'ready') if o.weapons.all? { |w| w.status == 'ready' } | |
| end | |
| end | |
| def aoas! | |
| if operations.all? { |o| o.status == 'success' } | |
| self.all_operations_are_success = true | |
| elsif operations.all? { |o| o.status == 'failed' } | |
| self.all_operations_are_success = false | |
| end | |
| end | |
| end | |
| class Operation << ActiveRecord::Base | |
| belongs_to :agent | |
| has_many :weapons | |
| has_many :operators | |
| end | |
| class Operator << ActiveRecord::Base | |
| belongs_to :operation | |
| end | |
| def OperationsController | |
| OPERATIONS = [] | |
| def prepare_operation | |
| @operations = [] | |
| @operations_id = operations.connection.execute("select id from where id = #{params[:id]}").values.flatten | |
| Operation.where(id: @operations_id).each do |operation| | |
| operation.agent.prepare_agent_for_operation | |
| OPERATIONS << operation | |
| end | |
| render json: OPERATIONS.to_json | |
| end | |
| def run_operation | |
| OPERATIONS.each do |operation| | |
| operation.update(status: 'running') | |
| end | |
| end | |
| def notify_operatiors | |
| current_agent.operators.map do |operator| | |
| operator.send_notification if operator.operation.status == 'running' | |
| end | |
| end | |
| def current_agent | |
| @current_agent ||= Agent.find(session[:agent_id]) | |
| end | |
| end | |
| array1 = [1, 9, 43, 5, 12, 2] | |
| array2 = [43, 12, 1, 5, 9, 2] | |
| array3 = [87, 12, 1, 5, 3, 2] | |
| def find_diff(array1, array2) | |
| #implementation | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment