Class: OpenC3::Schedule

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

Overview

Shared between the monitor thread and the manager thread to share the planned activities. This should remain a thread safe implementation.

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Schedule

Returns a new instance of Schedule.



164
165
166
167
168
169
170
171
# File 'lib/openc3/microservices/timeline_microservice.rb', line 164

def initialize(name)
  @name = name
  @activities_mutex = Mutex.new
  @activities = []
  @size = 20
  @queue = Array.new(@size)
  @index = 0
end

Instance Method Details

#activitiesObject



181
182
183
184
185
# File 'lib/openc3/microservices/timeline_microservice.rb', line 181

def activities
  @activities_mutex.synchronize do
    return @activities.dup
  end
end

#add_activity(input_activity) ⇒ Object



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

def add_activity(input_activity)
  @activities_mutex.synchronize do
    if @activities.find { |x| x.start == input_activity.start }.nil?
      @activities << input_activity
    end
  end
end

#not_queued?(start) ⇒ Boolean

Returns:

  • (Boolean)


173
174
175
176
177
178
179
# File 'lib/openc3/microservices/timeline_microservice.rb', line 173

def not_queued?(start)
  return false if @queue.index(start)

  @queue[@index] = start
  @index = @index + 1 >= @size ? 0 : @index + 1
  return true
end

#remove_activity(input_activity) ⇒ Object



201
202
203
204
205
# File 'lib/openc3/microservices/timeline_microservice.rb', line 201

def remove_activity(input_activity)
  @activities_mutex.synchronize do
    @activities.delete_if { |h| h.start == input_activity.start }
  end
end

#update(input_activities) ⇒ Object



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

def update(input_activities)
  @activities_mutex.synchronize do
    @activities = input_activities.dup
  end
end