Class: OpenC3::TextLogMicroservice
Instance Attribute Summary
Attributes inherited from Microservice
#count, #custom, #error, #logger, #microservice_status_thread, #name, #scope, #secrets, #state
Instance Method Summary
collapse
#as_json, run
Constructor Details
Returns a new instance of TextLogMicroservice.
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/openc3/microservices/text_log_microservice.rb', line 28
def initialize(name)
super(name)
@config['options'].each do |option|
case option[0].upcase
when 'CYCLE_TIME' @cycle_time = option[1].to_i
when 'CYCLE_SIZE' @cycle_size = option[1].to_i
else
@logger.error("Unknown option passed to microservice #{@name}: #{option}")
end
end
@cycle_time = 600 unless @cycle_time @cycle_size = 50_000_000 unless @cycle_size end
|
Instance Method Details
#log_data(topic, msg_id, msg_hash, redis) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/openc3/microservices/text_log_microservice.rb', line 70
def log_data(topic, msg_id, msg_hash, redis)
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
keys = msg_hash.keys
keys.delete("time")
entry = keys.reduce("") { |data, key| data + "#{key}: #{msg_hash[key]}\t" }
@tlws[topic].write(msg_hash["time"].to_i, entry, topic, msg_id)
@count += 1
diff = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start @metric.add_sample(name: "log_duration_seconds", value: diff, labels: {})
rescue => err
@error = err
@logger.error("#{@name} error: #{err.formatted}")
end
|
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/openc3/microservices/text_log_microservice.rb', line 46
def run
setup_tlws()
while true
break if @cancel_thread
Topic.read_topics(@topics) do |topic, msg_id, msg_hash, redis|
break if @cancel_thread
log_data(topic, msg_id, msg_hash, redis)
end
end
end
|
#setup_tlws ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/openc3/microservices/text_log_microservice.rb', line 59
def setup_tlws
@tlws = {}
@topics.each do |topic|
topic_split = topic.gsub(/{|}/, '').split("__") scope = topic_split[0]
log_name = topic_split[1]
remote_log_directory = "#{scope}/text_logs/#{log_name}"
@tlws[topic] = TextLogWriter.new(remote_log_directory, true, @cycle_time, @cycle_size, nil, nil, false)
end
end
|
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/openc3/microservices/text_log_microservice.rb', line 84
def shutdown
threads = []
@tlws.each do |topic, tlw|
threads.concat(tlw.shutdown)
end
threads.flatten.compact.each do |thread|
thread.join
end
super()
end
|