2020-10-17 21:25:57 +09:00
|
|
|
class Invidious::Jobs::NotificationJob < Invidious::Jobs::BaseJob
|
2022-11-12 08:04:27 +09:00
|
|
|
private getter connection_channel : ::Channel({Bool, ::Channel(PQ::Notification)})
|
2020-10-17 21:25:57 +09:00
|
|
|
private getter pg_url : URI
|
|
|
|
|
|
|
|
def initialize(@connection_channel, @pg_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
def begin
|
2022-11-12 08:04:27 +09:00
|
|
|
connections = [] of ::Channel(PQ::Notification)
|
2020-10-17 21:25:57 +09:00
|
|
|
|
|
|
|
PG.connect_listen(pg_url, "notifications") { |event| connections.each(&.send(event)) }
|
|
|
|
|
|
|
|
loop do
|
|
|
|
action, connection = connection_channel.receive
|
|
|
|
|
|
|
|
case action
|
|
|
|
when true
|
|
|
|
connections << connection
|
|
|
|
when false
|
|
|
|
connections.delete(connection)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|