Class: OpenC3::ScriptStatusModel
- Defined in:
- lib/openc3/models/script_status_model.rb
Constant Summary collapse
- RUNNING_PRIMARY_KEY =
Note: ScriptRunner only has permissions for keys that start with running-script
'running-script'- COMPLETED_PRIMARY_KEY =
'running-script-completed'
Instance Attribute Summary collapse
-
#current_filename ⇒ Object
Returns the value of attribute current_filename.
-
#disconnect ⇒ Object
Returns the value of attribute disconnect.
-
#end_line_no ⇒ Object
Returns the value of attribute end_line_no.
-
#end_time ⇒ Object
Returns the value of attribute end_time.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#line_no ⇒ Object
Returns the value of attribute line_no.
-
#log ⇒ Object
Returns the value of attribute log.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#report ⇒ Object
Returns the value of attribute report.
-
#script_engine ⇒ Object
Returns the value of attribute script_engine.
-
#shard ⇒ Object
Returns the value of attribute shard.
-
#start_line_no ⇒ Object
Returns the value of attribute start_line_no.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#state ⇒ Object
spawning, init, running, paused, waiting, breakpoint, error, crashed, stopped, completed, completed_errors, killed.
-
#suite_runner ⇒ Object
Returns the value of attribute suite_runner.
-
#user_full_name ⇒ Object
Returns the value of attribute user_full_name.
-
#username ⇒ Object
Returns the value of attribute username.
Attributes inherited from Model
#name, #plugin, #scope, #updated_at
Class Method Summary collapse
- .all(scope:, offset: 0, limit: 10, type: "running") ⇒ Object
- .count(scope:, type: "running") ⇒ Object
-
.get(name:, scope:, type: "auto") ⇒ Object
NOTE: The following three class methods are used by the ModelController and are reimplemented to enable various Model class methods to work.
- .names(scope:, type: "running") ⇒ Object
Instance Method Summary collapse
- #as_json(*a) ⇒ Object
-
#create(update: false, force: false, queued: false, isoformat: true) ⇒ Object
Update the Redis hash at primary_key and set the field “name” to the JSON generated via calling as_json.
-
#destroy(queued: false) ⇒ Object
Delete the model from the Store.
- #id ⇒ Object
-
#initialize(name:, state:, shard: 0, filename:, current_filename: nil, line_no: 0, start_line_no: 1, end_line_no: nil, username:, user_full_name:, start_time:, end_time: nil, disconnect: false, environment: nil, suite_runner: nil, errors: nil, pid: nil, log: nil, report: nil, script_engine: nil, updated_at: nil, scope:) ⇒ ScriptStatusModel
constructor
A new instance of ScriptStatusModel.
- #is_complete? ⇒ Boolean
- #update(force: false, queued: false) ⇒ Object
Methods inherited from Model
#check_disable_erb, #deploy, #destroyed?, #diff, filter, find_all_by_plugin, from_json, get_all_models, get_model, handle_config, set, store, store_queued, #undeploy
Constructor Details
#initialize(name:, state:, shard: 0, filename:, current_filename: nil, line_no: 0, start_line_no: 1, end_line_no: nil, username:, user_full_name:, start_time:, end_time: nil, disconnect: false, environment: nil, suite_runner: nil, errors: nil, pid: nil, log: nil, report: nil, script_engine: nil, updated_at: nil, scope:) ⇒ ScriptStatusModel
Returns a new instance of ScriptStatusModel.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/openc3/models/script_status_model.rb', line 126 def initialize( name:, # id state:, # spawning, init, running, paused, waiting, error, breakpoint, crashed, stopped, completed, completed_errors, killed shard: 0, # Future enhancement of script runner shards filename:, # The initial filename current_filename: nil, # The current filename line_no: 0, # The current line number start_line_no: 1, # The line number to start the script at end_line_no: nil, # The line number to end the script at username:, # The username of the person who started the script user_full_name:, # The full name of the person who started the script start_time:, # The time the script started ISO format end_time: nil, # The time the script ended ISO format disconnect: false, environment: nil, suite_runner: nil, errors: nil, pid: nil, log: nil, report: nil, script_engine: nil, updated_at: nil, scope: ) @state = state if is_complete?() super("#{COMPLETED_PRIMARY_KEY}__#{scope}", name: name, updated_at: updated_at, plugin: nil, scope: scope) else super("#{RUNNING_PRIMARY_KEY}__#{scope}", name: name, updated_at: updated_at, plugin: nil, scope: scope) end @shard = shard.to_i @filename = filename @current_filename = current_filename @line_no = line_no @start_line_no = start_line_no @end_line_no = end_line_no @username = username @user_full_name = user_full_name @start_time = start_time @end_time = end_time @disconnect = disconnect @environment = environment @suite_runner = suite_runner @errors = errors @pid = pid @log = log @report = report @script_engine = script_engine end |
Instance Attribute Details
#current_filename ⇒ Object
Returns the value of attribute current_filename.
28 29 30 |
# File 'lib/openc3/models/script_status_model.rb', line 28 def current_filename @current_filename end |
#disconnect ⇒ Object
Returns the value of attribute disconnect.
36 37 38 |
# File 'lib/openc3/models/script_status_model.rb', line 36 def disconnect @disconnect end |
#end_line_no ⇒ Object
Returns the value of attribute end_line_no.
31 32 33 |
# File 'lib/openc3/models/script_status_model.rb', line 31 def end_line_no @end_line_no end |
#end_time ⇒ Object
Returns the value of attribute end_time.
35 36 37 |
# File 'lib/openc3/models/script_status_model.rb', line 35 def end_time @end_time end |
#environment ⇒ Object
Returns the value of attribute environment.
37 38 39 |
# File 'lib/openc3/models/script_status_model.rb', line 37 def environment @environment end |
#errors ⇒ Object
Returns the value of attribute errors.
39 40 41 |
# File 'lib/openc3/models/script_status_model.rb', line 39 def errors @errors end |
#filename ⇒ Object
Returns the value of attribute filename.
27 28 29 |
# File 'lib/openc3/models/script_status_model.rb', line 27 def filename @filename end |
#line_no ⇒ Object
Returns the value of attribute line_no.
29 30 31 |
# File 'lib/openc3/models/script_status_model.rb', line 29 def line_no @line_no end |
#log ⇒ Object
Returns the value of attribute log.
41 42 43 |
# File 'lib/openc3/models/script_status_model.rb', line 41 def log @log end |
#pid ⇒ Object
Returns the value of attribute pid.
40 41 42 |
# File 'lib/openc3/models/script_status_model.rb', line 40 def pid @pid end |
#report ⇒ Object
Returns the value of attribute report.
42 43 44 |
# File 'lib/openc3/models/script_status_model.rb', line 42 def report @report end |
#script_engine ⇒ Object
Returns the value of attribute script_engine.
43 44 45 |
# File 'lib/openc3/models/script_status_model.rb', line 43 def script_engine @script_engine end |
#shard ⇒ Object
Returns the value of attribute shard.
26 27 28 |
# File 'lib/openc3/models/script_status_model.rb', line 26 def shard @shard end |
#start_line_no ⇒ Object
Returns the value of attribute start_line_no.
30 31 32 |
# File 'lib/openc3/models/script_status_model.rb', line 30 def start_line_no @start_line_no end |
#start_time ⇒ Object
Returns the value of attribute start_time.
34 35 36 |
# File 'lib/openc3/models/script_status_model.rb', line 34 def start_time @start_time end |
#state ⇒ Object
spawning, init, running, paused, waiting, breakpoint, error, crashed, stopped, completed, completed_errors, killed
25 26 27 |
# File 'lib/openc3/models/script_status_model.rb', line 25 def state @state end |
#suite_runner ⇒ Object
Returns the value of attribute suite_runner.
38 39 40 |
# File 'lib/openc3/models/script_status_model.rb', line 38 def suite_runner @suite_runner end |
#user_full_name ⇒ Object
Returns the value of attribute user_full_name.
33 34 35 |
# File 'lib/openc3/models/script_status_model.rb', line 33 def user_full_name @user_full_name end |
#username ⇒ Object
Returns the value of attribute username.
32 33 34 |
# File 'lib/openc3/models/script_status_model.rb', line 32 def username @username end |
Class Method Details
.all(scope:, offset: 0, limit: 10, type: "running") ⇒ Object
64 65 66 67 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/openc3/models/script_status_model.rb', line 64 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 = [] if $openc3_redis_cluster # No pipelining for cluster mode # because it requires using the same shard for all keys keys.each do |key| result << self.store.hget("#{RUNNING_PRIMARY_KEY}__#{scope}", key) end else result = self.store.redis_pool.pipelined do keys.each do |key| self.store.hget("#{RUNNING_PRIMARY_KEY}__#{scope}", key) end 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 = [] if $openc3_redis_cluster # No pipelining for cluster mode # because it requires using the same shard for all keys keys.each do |key| result << self.store.hget("#{COMPLETED_PRIMARY_KEY}__#{scope}", key) end else result = self.store.redis_pool.pipelined do keys.each do |key| self.store.hget("#{COMPLETED_PRIMARY_KEY}__#{scope}", key) end 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 |
.count(scope:, type: "running") ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/openc3/models/script_status_model.rb', line 118 def self.count(scope:, type: "running") if type == "running" return self.store.zcount("#{RUNNING_PRIMARY_KEY}__#{scope}__LIST", 0, Float::INFINITY) else return self.store.zcount("#{COMPLETED_PRIMARY_KEY}__#{scope}__LIST", 0, Float::INFINITY) end end |
.get(name:, scope:, type: "auto") ⇒ Object
NOTE: The following three class methods are used by the ModelController and are reimplemented to enable various Model class methods to work
47 48 49 50 51 52 53 54 |
# File 'lib/openc3/models/script_status_model.rb', line 47 def self.get(name:, scope:, type: "auto") if type == "auto" or type == "running" # Check for running first running = super("#{RUNNING_PRIMARY_KEY}__#{scope}", name: name) return running if running end return super("#{COMPLETED_PRIMARY_KEY}__#{scope}", name: name) end |
.names(scope:, type: "running") ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/openc3/models/script_status_model.rb', line 56 def self.names(scope:, type: "running") if type == "running" return super("#{RUNNING_PRIMARY_KEY}__#{scope}") else return super("#{COMPLETED_PRIMARY_KEY}__#{scope}") end end |
Instance Method Details
#as_json(*a) ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/openc3/models/script_status_model.rb', line 237 def as_json(*a) { 'name' => @name, 'state' => @state, 'shard' => @shard, 'filename' => @filename, 'current_filename' => @current_filename, 'line_no' => @line_no, 'start_line_no' => @start_line_no, 'end_line_no' => @end_line_no, 'username' => @username, 'user_full_name' => @user_full_name, 'start_time' => @start_time, 'end_time' => @end_time, 'disconnect' => @disconnect, 'environment' => @environment, 'suite_runner' => @suite_runner, 'errors' => @errors, 'pid' => @pid, 'log' => @log, 'report' => @report, 'script_engine' => @script_engine, 'updated_at' => @updated_at, 'scope' => @scope } end |
#create(update: false, force: false, queued: false, isoformat: true) ⇒ Object
Update the Redis hash at primary_key and set the field “name” to the JSON generated via calling as_json
194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/openc3/models/script_status_model.rb', line 194 def create(update: false, force: false, queued: false, isoformat: true) @updated_at = Time.now.utc.to_nsec_from_epoch if queued write_store = self.class.store_queued else write_store = self.class.store end write_store.hset(@primary_key, @name, JSON.generate(self.as_json(), allow_nan: true)) # Also add to ordered set on create write_store.zadd(@primary_key + "__LIST", @name.to_i, @name) if not update end |
#destroy(queued: false) ⇒ Object
Delete the model from the Store
224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/openc3/models/script_status_model.rb', line 224 def destroy(queued: false) @destroyed = true undeploy() if queued write_store = self.class.store_queued else write_store = self.class.store end write_store.hdel(@primary_key, @name) # Also remove from ordered set write_store.zremrangebyscore(@primary_key + "__LIST", @name.to_i, @name.to_i) end |
#id ⇒ Object
22 23 24 |
# File 'lib/openc3/models/script_status_model.rb', line 22 def id return @name end |
#is_complete? ⇒ Boolean
176 177 178 |
# File 'lib/openc3/models/script_status_model.rb', line 176 def is_complete? return (@state == 'completed' or @state == 'completed_errors' or @state == 'stopped' or @state == 'crashed' or @state == 'killed') end |
#update(force: false, queued: false) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/openc3/models/script_status_model.rb', line 208 def update(force: false, queued: false) # Magically handle the change from running to completed if is_complete?() and @primary_key == "#{RUNNING_PRIMARY_KEY}__#{@scope}" # Destroy the running key destroy(queued: queued) @destroyed = false # Move to completed @primary_key = "#{COMPLETED_PRIMARY_KEY}__#{@scope}" create(update: false, force: force, queued: queued, isoformat: true) else create(update: true, force: force, queued: queued, isoformat: true) end end |