Class: OpenC3::SnoozeBase

Inherits:
Object show all
Defined in:
lib/openc3/microservices/reaction_microservice.rb

Overview

This should remain a thread safe implementation.

Instance Method Summary collapse

Constructor Details

#initialize(scope:) ⇒ SnoozeBase

Returns a new instance of SnoozeBase.



185
186
187
188
189
190
191
# File 'lib/openc3/microservices/reaction_microservice.rb', line 185

def initialize(scope:)
  # store the round robin watch
  @watch_mutex = Mutex.new
  @watch_size = 25
  @watch_queue = Array.new(@watch_size)
  @watch_index = 0
end

Instance Method Details

#not_queued?(reaction:) ⇒ Boolean

Returns:

  • (Boolean)


193
194
195
196
197
198
199
200
201
# File 'lib/openc3/microservices/reaction_microservice.rb', line 193

def not_queued?(reaction:)
  key = "#{reaction.name}__#{reaction.snoozed_until}"
  @watch_mutex.synchronize do
    return false if @watch_queue.index(key)
    @watch_queue[@watch_index] = key
    @watch_index = @watch_index + 1 >= @watch_size ? 0 : @watch_index + 1
    return true
  end
end