38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/openc3/microservices/cleanup_microservice.rb', line 38
def run
split_name = @name.split("__")
target_name = split_name[-1]
target = TargetModel.get_model(name: target_name, scope: @scope)
bucket = Bucket.getClient()
while true
break if @cancel_thread
@state = 'GETTING_OBJECTS'
start_time = Time.now
[
["#{@scope}/raw_logs/cmd/#{target_name}", target.cmd_log_retain_time],
["#{@scope}/decom_logs/cmd/#{target_name}", target.cmd_decom_log_retain_time],
["#{@scope}/raw_logs/tlm/#{target_name}", target.tlm_log_retain_time],
["#{@scope}/decom_logs/tlm/#{target_name}", target.tlm_decom_log_retain_time],
["#{@scope}/reduced_minute_logs/tlm/#{target_name}", target.reduced_minute_log_retain_time],
["#{@scope}/reduced_hour_logs/tlm/#{target_name}", target.reduced_hour_log_retain_time],
["#{@scope}/reduced_day_logs/tlm/#{target_name}", target.reduced_day_log_retain_time],
].each do |prefix, retain_time|
next unless retain_time
time = start_time - retain_time
oldest_list = BucketUtilities.files_between_time(ENV['OPENC3_LOGS_BUCKET'], prefix, nil, time)
if oldest_list.length > 0
@state = 'DELETING_OBJECTS'
oldest_list.each_slice(1000) do |slice|
bucket.delete_objects(bucket: ENV['OPENC3_LOGS_BUCKET'], keys: slice)
@logger.info("Deleted #{slice.length} #{target_name} log files")
@delete_count += slice.length
@metric.set(name: 'cleanup_delete_total', value: @delete_count, type: 'counter')
end
end
end
@count += 1
@metric.set(name: 'cleanup_total', value: @count, type: 'counter')
@state = 'SLEEPING'
break if @sleeper.sleep(target.cleanup_poll_time)
end
end
|