Method: OpenC3::ActivityModel#update
- Defined in:
- lib/openc3/models/activity_model.rb
#update(start:, stop:, kind:, data:) ⇒ 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. The member via the JSON generated via calling as_json
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/openc3/models/activity_model.rb', line 229 def update(start:, stop:, kind:, data:) array = Store.zrangebyscore(@primary_key, @start, @start) if array.length == 0 raise ActivityError.new "failed to find activity at: #{@start}" end validate_input(start: start, stop: stop, kind: kind, data: data) old_start = @start set_input(start: start, stop: stop, kind: kind, data: data, events: @events) @updated_at = Time.now.to_nsec_from_epoch # copy of create collision = validate_time(old_start) unless collision.nil? raise ActivityOverlapError.new "failed to update #{old_start}, no activities can overlap, collision: #{collision}" end add_event(status: 'updated') Store.multi do |multi| multi.zremrangebyscore(@primary_key, old_start, old_start) multi.zadd(@primary_key, @start, JSON.generate(self.as_json(:allow_nan => true))) end notify(kind: 'updated', extra: old_start) return @start end |