From b9cfae8c6b58ad72cd3344bef55562592cc884dd Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Fri, 12 Nov 2021 06:33:44 +0000 Subject: [PATCH] move mail event loop to Feeder --- bin/mpd-feeder | 18 +----------------- lib/App/MPD/Feeder.pm | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/bin/mpd-feeder b/bin/mpd-feeder index 53c8265..79d0b1b 100755 --- a/bin/mpd-feeder +++ b/bin/mpd-feeder @@ -70,20 +70,4 @@ if (@ARGV) { } } -$feeder->connect_db; - -for ( ;; ) { - $feeder->queue_songs( undef, sub { $feeder->run } ); - - $log->debug("Entering event loop. PID=$$"); - - my $result = $feeder->mpd->loop->run; - $log->trace( "Got loop result of " . ( $result // 'undef' ) ); - - if ('reload' eq $result) { - $log->notice("disconnecting"); - $feeder->stop; - - exec( "$0", '--config', $feeder->cfg_file, '--skip-db-update' ); - } -} +$feeder->run_loop; diff --git a/lib/App/MPD/Feeder.pm b/lib/App/MPD/Feeder.pm index dbdcafb..4285e70 100644 --- a/lib/App/MPD/Feeder.pm +++ b/lib/App/MPD/Feeder.pm @@ -482,5 +482,25 @@ SQL undef $db; } } + + method run_loop { + $self->connect_db; + + for ( ;; ) { + $self->queue_songs( undef, sub { $self->run } ); + + $log->debug("Entering event loop. PID=$$"); + + my $result = $mpd->loop->run; + $log->trace( "Got loop result of " . ( $result // 'undef' ) ); + + if ( 'reload' eq $result ) { + $log->notice("disconnecting"); + $self->stop; + + exec( "$0", '--config', $self->cfg_file, '--skip-db-update' ); + } + } + } } -- 2.39.5