Method: OpenC3::ActivityModel#update
- Defined in:
- lib/openc3/models/activity_model.rb
#update(start:, stop:, kind:, data:, overlap: true) ⇒ Object
Update the Redis hash at primary_key and remove the current activity at the current score and update the score to the new score equal to the start Epoch time this uses a multi to execute both the remove and create.
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/openc3/models/activity_model.rb', line 342 def update(start:, stop:, kind:, data:, overlap: true) array = Store.zrangebyscore(@primary_key, @start, @start) if array.length == 0 raise ActivityError.new "failed to find activity at: #{@start}" end old_start = @start old_uuid = @uuid unless overlap # If we don't allow overlap we need to validate the time collision = validate_time(start, stop, ignore_score: old_start) unless collision.nil? raise ActivityOverlapError.new "failed to update #{old_start}, no activities can overlap, collision: #{collision}" end end set_input(start: start, stop: stop, kind: kind, data: data, events: @events) @updated_at = Time.now.to_nsec_from_epoch add_event(status: 'updated') json = Store.zrangebyscore(@primary_key, old_start, old_start) parsed = json.map { |value| JSON.parse(value, :allow_nan => true, :create_additions => true) } parsed.each_with_index do |value, index| if value['uuid'] == old_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: 'updated', extra: {old_start: old_start, old_uuid: old_uuid}) return @start end |