Method: OpenC3::ScriptStatusModel.all

Defined in:
lib/openc3/models/script_status_model.rb

.all(scope:, offset: 0, limit: 10, type: "running") ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/openc3/models/script_status_model.rb', line 68

def self.all(scope:, offset: 0, limit: 10, type: "running")
  if type == "running"
    keys = self.store.zrevrange("#{RUNNING_PRIMARY_KEY}__#{scope}__LIST", offset.to_i, offset.to_i + limit.to_i - 1)
    return [] if keys.empty?
    result = self.store.redis_pool.pipelined do
      keys.each do |key|
        self.store.hget("#{RUNNING_PRIMARY_KEY}__#{scope}", key)
      end
    end
    result = result.map do |r|
      if r.nil?
        nil
      else
        JSON.parse(r, :allow_nan => true, :create_additions => true)
      end
    end
    return result
  else
    keys = self.store.zrevrange("#{COMPLETED_PRIMARY_KEY}__#{scope}__LIST", offset.to_i, offset.to_i + limit.to_i - 1)
    return [] if keys.empty?
    result = self.store.redis_pool.pipelined do
      keys.each do |key|
        self.store.hget("#{COMPLETED_PRIMARY_KEY}__#{scope}", key)
      end
    end
    result = result.map do |r|
      if r.nil?
        nil
      else
        JSON.parse(r, :allow_nan => true, :create_additions => true)
      end
    end
    return result
  end
end