2022-12-07 03:37:33 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ActivityLogger
|
|
|
|
|
2023-01-13 03:48:04 +09:00
|
|
|
@@loggers = Hash.new { |hash, key| hash[key] = [] }
|
2022-12-07 03:37:33 +09:00
|
|
|
|
|
|
|
def self.register(id, sse)
|
2023-01-13 03:48:04 +09:00
|
|
|
@@loggers[id] << sse
|
2022-12-07 03:37:33 +09:00
|
|
|
end
|
|
|
|
|
2023-01-13 03:48:04 +09:00
|
|
|
def self.unregister(id, sse)
|
|
|
|
@@loggers[id].delete(sse)
|
2022-12-07 03:37:33 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.log(id, event)
|
2023-01-15 01:12:20 +09:00
|
|
|
@@loggers[id].each do |logger|
|
|
|
|
logger.write event
|
|
|
|
rescue
|
|
|
|
puts 'rescued'
|
|
|
|
end
|
2023-01-13 03:48:04 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.reset
|
|
|
|
@@loggers.clear
|
2022-12-07 03:37:33 +09:00
|
|
|
end
|
|
|
|
end
|