activitypub-academy/app/lib/activity_logger.rb

27 lines
417 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class ActivityLogger
2023-01-13 03:48:04 +09:00
@@loggers = Hash.new { |hash, key| hash[key] = [] }
def self.register(id, sse)
2023-01-13 03:48:04 +09:00
@@loggers[id] << sse
end
2023-01-13 03:48:04 +09:00
def self.unregister(id, sse)
@@loggers[id].delete(sse)
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
end
end