Base timer, grooming.

This commit is contained in:
Karchnu 2020-12-13 03:18:30 +01:00
parent 7f5d162e91
commit 7c1d6af93a

View File

@ -40,9 +40,7 @@ class DNSManager::Service < IPC::Server
end end
def get_logged_user(event : IPC::Event::Events) def get_logged_user(event : IPC::Event::Events)
fd = event.fd @logged_users[event.fd]?
@logged_users[fd]?
end end
def decode_token(token : String) def decode_token(token : String)
@ -50,6 +48,8 @@ class DNSManager::Service < IPC::Server
end end
def handle_request(event : IPC::Event::MessageReceived) def handle_request(event : IPC::Event::MessageReceived)
pp! "hello", event
request_start = Time.utc request_start = Time.utc
request = DNSManager.requests.parse_ipc_json event.message request = DNSManager.requests.parse_ipc_json event.message
@ -99,6 +99,9 @@ class DNSManager::Service < IPC::Server
def run def run
Baguette::Log.title "Starting #{@configuration.service_name}" Baguette::Log.title "Starting #{@configuration.service_name}"
@base_timer = configuration.ipc_timer
@timer = configuration.ipc_timer
self.loop do |event| self.loop do |event|
begin begin
case event case event
@ -110,20 +113,26 @@ class DNSManager::Service < IPC::Server
when IPC::Event::Disconnection when IPC::Event::Disconnection
Baguette::Log.debug "disconnection from #{event.fd}" Baguette::Log.debug "disconnection from #{event.fd}"
fd = event.fd @logged_users.delete event.fd
@logged_users.delete fd
when IPC::Event::MessageSent when IPC::Event::MessageSent
Baguette::Log.debug "message sent to #{event.fd}" Baguette::Log.debug "message sent to #{event.fd}"
when IPC::Event::MessageReceived when IPC::Event::MessageReceived
Baguette::Log.debug "message sent to #{event.fd}" Baguette::Log.debug "message received from #{event.fd}"
handle_request event handle_request event
else else
Baguette::Log.warning "unhandled IPC event: #{event.class}" Baguette::Log.warning "unhandled IPC event: #{event.class}"
if event.responds_to?(:fd)
fd = event.fd
Baguette::Log.warning "closing #{fd}"
remove_fd fd
@logged_users.delete fd
end end
end
rescue exception rescue exception
Baguette::Log.error "exception: #{typeof(exception)} - #{exception.message}" Baguette::Log.error "exception: #{typeof(exception)} - #{exception.message}"
end end