Module: Legion::API::Routes::Fleet::FleetHelpers
- Defined in:
- lib/legion/api/fleet.rb
Instance Method Summary collapse
- #fleet_add_source(body) ⇒ Object
- #fleet_approve(_id) ⇒ Object
- #fleet_pending_approvals ⇒ Object
- #fleet_queue_depth(queue_name) ⇒ Object
- #fleet_setup_github_source(body) ⇒ Object
- #fleet_status ⇒ Object
Instance Method Details
#fleet_add_source(body) ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/legion/api/fleet.rb', line 102 def fleet_add_source(body) source = body[:source] case source when 'github' fleet_setup_github_source(body) else { success: false, error: "Unknown source: #{source}" } end end |
#fleet_approve(_id) ⇒ Object
98 99 100 |
# File 'lib/legion/api/fleet.rb', line 98 def fleet_approve(_id) { success: false, error: 'approval system not available' } end |
#fleet_pending_approvals ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/legion/api/fleet.rb', line 78 def fleet_pending_approvals approval_types = %w[fleet.shipping fleet.escalation] if defined?(Legion::Data::Model::Task) Legion::Data::Model::Task .where(status: 'pending_approval') .where(Sequel.lit('JSON_EXTRACT(payload, ?) IN ?', '$.approval_type', approval_types)) .order(Sequel.desc(:created_at)) .limit(page_limit) .all .map(&:values) else [] end rescue StandardError => e Legion::Logging.warn "Fleet#fleet_pending_approvals: #{e.}" if defined?(Legion::Logging) [] end |
#fleet_queue_depth(queue_name) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/legion/api/fleet.rb', line 68 def fleet_queue_depth(queue_name) return nil unless defined?(Legion::Transport::Session) channel = Legion::Transport::Session.channel queue = channel.queue(queue_name, passive: true) queue. rescue StandardError nil end |
#fleet_setup_github_source(body) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/legion/api/fleet.rb', line 112 def fleet_setup_github_source(body) sources = Legion::Settings.dig(:fleet, :sources) || [] entry = { type: 'github', owner: body[:owner], repo: body[:repo] } sources << entry Legion::Settings.loader.settings[:fleet] ||= {} Legion::Settings.loader.settings[:fleet][:sources] = sources { success: true, source: 'github', absorber: 'issues' } rescue StandardError => e { success: false, error: e. } end |
#fleet_status ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/legion/api/fleet.rb', line 52 def fleet_status queues = [] active = 0 workers = 0 if defined?(Legion::Transport) && Legion::Settings.dig(:transport, :connected) %w[assessor planner developer validator].each do |ext| queue_name = "lex.#{ext}.runners.#{ext}" depth = fleet_queue_depth(queue_name) queues << { name: queue_name, depth: depth } if depth end end { queues: queues, active_work_items: active, workers: workers } end |