Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rawleyfowler committed Mar 2, 2024
2 parents 77facd5 + 869e92e commit a8b062a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
5 changes: 5 additions & 0 deletions META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
"Humming-Bird::Plugin::Config": "lib/Humming-Bird/Plugin/Config.rakumod",
"Humming-Bird::Plugin::Logger": "lib/Humming-Bird/Plugin/Logger.rakumod",
"Humming-Bird::Plugin::Session": "lib/Humming-Bird/Plugin/Session.rakumod",
<<<<<<< HEAD
"Humming-Bird::Plugin::DBIish": "lib/Humming-Bird/Plugin/DBIish.rakumod"
=======
"Humming-Bird::Plugin::DBIish": "lib/Humming-Bird/Plugin/DBIish.rakumod",
"Humming-Bird::Plugin::HotReload": "lib/Humming-Bird/Plugin/HotReload.rakumod"
>>>>>>> dbiish
},
"resources": [
],
Expand Down
9 changes: 8 additions & 1 deletion lib/Humming-Bird/Backend/HTTPServer.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ my constant $RN = "\r\n".encode.Buf;
has Channel:D $.requests .= new;
has Lock $!lock .= new;
has @!connections;
has $!conn-channel;

method close {
$_.close for @!connections;
$!conn-channel.close;
}

method !timeout {
start {
Expand Down Expand Up @@ -69,7 +75,8 @@ method listen(&handler) {
react {
self!timeout;
self!respond(&handler);
whenever IO::Socket::Async.listen($.addr // '0.0.0.0', $.port) -> $connection {
$!conn-channel = IO::Socket::Async.listen($.addr // '0.0.0.0', $.port).Channel;
whenever $!conn-channel -> $connection {
my %connection-map := {
socket => $connection,
last-active => now
Expand Down
1 change: 0 additions & 1 deletion lib/Humming-Bird/Plugin/DBIish.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ method register($server, %routes, @middleware, @advice, **@args) {

my $dh = $dbiish.install-driver(shift @database-args);

say @database-args;
%databases{$database-name} = $dh.connect(|%(|@database-args));

CATCH {
Expand Down
21 changes: 10 additions & 11 deletions lib/Humming-Bird/Plugin/HotReload.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,27 @@ class Humming-Bird::Backend::HotReload does Humming-Bird::Backend {
self!start-server();

react whenever $!reload-chan -> $reload {
$.backend.close;
self!start-server();
if ($reload === True) {
$.backend.close;
self!start-server();
}
}
}

method !start-server {
start {
listen(self.port, self.addr, );
listen(self.port, self.addr);
}
}

method !observe {

react whenever IO::Notification.watch-path('.') {
say "$^file changed, reloading Humming-Bird...";
$!reload-chan.send: True;
}
}
}

method register($server is rw, %routes, @middleware, @advice, **@args) {
die 'Humming-Bird::Backend::HotRealod is WIP. Please do not use it yet.';
$server = Humming-Bird::Backend::HotReload.new(backend => $server);
CATCH {
default {
warn 'Failed to find or parse your ".humming-bird.json" configuration. Ensure your file is well formed, and does exist.';
}
}
$server := Humming-Bird::Backend::HotReload.new(backend => $server, timeout => 3);
}
6 changes: 3 additions & 3 deletions t/13-plugin.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class TestBackend does Humming-Bird::Backend {
}
}

lives-ok sub { plugin('Config', 't/static/.humming-bird.json'); }, 'Does plugin not die?';
lives-ok sub { plugin 'Logger'; }, 'Does other plugin not die?';
lives-ok sub { plugin 'Session'; }, 'Does other plugin not die?';
lives-ok sub { plugin('Config', 't/static/.humming-bird.json'); }, 'Does Config plugin not die?';
lives-ok sub { plugin 'Logger'; }, 'Does Logger plugin not die?';
lives-ok sub { plugin 'Session'; }, 'Does Session plugin not die?';
lives-ok sub { listen(8080, :backend(TestBackend)); }, 'Does plugin register ok?';
ok Humming-Bird::Glue::HTTPAction.^can('config'), 'Did plugin properly run?';

Expand Down
12 changes: 12 additions & 0 deletions t/14-hotreload.rakutest
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use v6;
use lib 'lib';
use Test;
use Humming-Bird::Core;
use Humming-Bird::Glue;
use Humming-Bird::Backend;
use Humming-Bird::Middleware;
use Humming-Bird::Advice;

plan 1;

lives-ok { plugin 'HotReload' }, 'Does HotReload plugin live ok?';

0 comments on commit a8b062a

Please sign in to comment.