Method: OpenC3::ActivityModel#commit

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

#commit(status:, message: nil, fulfillment: nil) ⇒ Object

commit will make an event and save the object to the redis database

Parameters:

  • status (String)
    • the event status such as "complete" or "failed"

  • message (String) (defaults to: nil)
    • an optional message to include in the event



378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'lib/openc3/models/activity_model.rb', line 378

def commit(status:, message: nil, fulfillment: nil)
  event = {
    'time' => Time.now.to_i,
    'event' => status,
    'commit' => true
  }
  event['message'] = message unless message.nil?
  @fulfillment = fulfillment.nil? ? @fulfillment : fulfillment
  @events << event

  json = Store.zrangebyscore(@primary_key, @start, @start)
  parsed = json.map { |value| JSON.parse(value, :allow_nan => true, :create_additions => true) }
  parsed.each_with_index do |value, index|
    if value['uuid'] == @uuid
      Store.multi do |multi|
        multi.zrem(@primary_key, json[index])
        multi.zadd(@primary_key, @start, JSON.generate(self.as_json(:allow_nan => true)))
      end
    end
  end
  notify(kind: 'event')
end