Hello community,

here is the log from the commit of package perl-Mojo-Pg for openSUSE:Factory 
checked in at 2018-12-12 17:27:07
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/perl-Mojo-Pg (Old)
 and      /work/SRC/openSUSE:Factory/.perl-Mojo-Pg.new.28833 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "perl-Mojo-Pg"

Wed Dec 12 17:27:07 2018 rev:16 rq:655784 version:4.12

Changes:
--------
--- /work/SRC/openSUSE:Factory/perl-Mojo-Pg/perl-Mojo-Pg.changes        
2018-11-15 12:40:43.874230828 +0100
+++ /work/SRC/openSUSE:Factory/.perl-Mojo-Pg.new.28833/perl-Mojo-Pg.changes     
2018-12-12 17:27:09.582977735 +0100
@@ -1,0 +2,11 @@
+Thu Dec  6 15:54:58 UTC 2018 - Stephan Kulow <co...@suse.com>
+
+- updated to 4.12
+   see /usr/share/doc/packages/perl-Mojo-Pg/Changes
+
+  4.12  2018-11-24
+    - Added reconnect_interval attribute to Mojo::Pg::PubSub. (jberger)
+    - Added db method to Mojo::Pg::PubSub. (jberger)
+    - Fixed reconnect logic in Mojo::Pg::PubSub. (jberger)
+
+-------------------------------------------------------------------

Old:
----
  Mojo-Pg-4.11.tar.gz

New:
----
  Mojo-Pg-4.12.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ perl-Mojo-Pg.spec ++++++
--- /var/tmp/diff_new_pack.6OLbGt/_old  2018-12-12 17:27:10.270976862 +0100
+++ /var/tmp/diff_new_pack.6OLbGt/_new  2018-12-12 17:27:10.270976862 +0100
@@ -17,7 +17,7 @@
 
 
 Name:           perl-Mojo-Pg
-Version:        4.11
+Version:        4.12
 Release:        0
 %define cpan_name Mojo-Pg
 Summary:        Wrapper around DBD::Pg for using PostgreSql with Mojolicious
@@ -54,10 +54,10 @@
 
 %build
 perl Makefile.PL INSTALLDIRS=vendor
-%{__make} %{?_smp_mflags}
+make %{?_smp_mflags}
 
 %check
-%{__make} test
+make test
 
 %install
 %perl_make_install

++++++ Mojo-Pg-4.11.tar.gz -> Mojo-Pg-4.12.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Mojo-Pg-4.11/Changes new/Mojo-Pg-4.12/Changes
--- old/Mojo-Pg-4.11/Changes    2018-10-18 01:16:48.000000000 +0200
+++ new/Mojo-Pg-4.12/Changes    2018-11-24 12:41:14.000000000 +0100
@@ -1,4 +1,9 @@
 
+4.12  2018-11-24
+  - Added reconnect_interval attribute to Mojo::Pg::PubSub. (jberger)
+  - Added db method to Mojo::Pg::PubSub. (jberger)
+  - Fixed reconnect logic in Mojo::Pg::PubSub. (jberger)
+
 4.11  2018-10-18
   - Improved various attributes to use new Mojolicious 8.03 features to avoid
     memory leaks.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Mojo-Pg-4.11/META.json new/Mojo-Pg-4.12/META.json
--- old/Mojo-Pg-4.11/META.json  2018-10-18 01:17:38.000000000 +0200
+++ new/Mojo-Pg-4.12/META.json  2018-11-24 18:05:16.000000000 +0100
@@ -57,6 +57,6 @@
       },
       "x_IRC" : "irc://irc.freenode.net/#mojo"
    },
-   "version" : "4.11",
+   "version" : "4.12",
    "x_serialization_backend" : "JSON::PP version 2.97001"
 }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Mojo-Pg-4.11/META.yml new/Mojo-Pg-4.12/META.yml
--- old/Mojo-Pg-4.11/META.yml   2018-10-18 01:17:38.000000000 +0200
+++ new/Mojo-Pg-4.12/META.yml   2018-11-24 18:05:16.000000000 +0100
@@ -30,5 +30,5 @@
   homepage: https://mojolicious.org
   license: http://www.opensource.org/licenses/artistic-license-2.0
   repository: https://github.com/mojolicious/mojo-pg.git
-version: '4.11'
+version: '4.12'
 x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Mojo-Pg-4.11/lib/Mojo/Pg/Database.pm 
new/Mojo-Pg-4.12/lib/Mojo/Pg/Database.pm
--- old/Mojo-Pg-4.11/lib/Mojo/Pg/Database.pm    2018-10-18 01:15:05.000000000 
+0200
+++ new/Mojo-Pg-4.12/lib/Mojo/Pg/Database.pm    2018-11-22 21:26:38.000000000 
+0100
@@ -11,7 +11,7 @@
 use Mojo::Util 'monkey_patch';
 
 has 'dbh';
-has pg => undef, weak => 1;
+has pg            => undef, weak => 1;
 has results_class => 'Mojo::Pg::Results';
 
 for my $name (qw(delete insert select update)) {
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Mojo-Pg-4.11/lib/Mojo/Pg/Migrations.pm 
new/Mojo-Pg-4.12/lib/Mojo/Pg/Migrations.pm
--- old/Mojo-Pg-4.11/lib/Mojo/Pg/Migrations.pm  2018-10-18 01:11:43.000000000 
+0200
+++ new/Mojo-Pg-4.12/lib/Mojo/Pg/Migrations.pm  2018-11-22 21:26:39.000000000 
+0100
@@ -9,7 +9,7 @@
 use constant DEBUG => $ENV{MOJO_MIGRATIONS_DEBUG} || 0;
 
 has name => 'migrations';
-has pg => undef, weak => 1;
+has pg   => undef, weak => 1;
 
 sub active { $_[0]->_active($_[0]->pg->db) }
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Mojo-Pg-4.11/lib/Mojo/Pg/PubSub.pm 
new/Mojo-Pg-4.12/lib/Mojo/Pg/PubSub.pm
--- old/Mojo-Pg-4.11/lib/Mojo/Pg/PubSub.pm      2018-10-18 01:14:49.000000000 
+0200
+++ new/Mojo-Pg-4.12/lib/Mojo/Pg/PubSub.pm      2018-11-24 12:40:08.000000000 
+0100
@@ -4,7 +4,31 @@
 use Mojo::JSON qw(from_json to_json);
 use Scalar::Util 'weaken';
 
-has pg => undef, weak => 1;
+has pg                 => undef, weak => 1;
+has reconnect_interval => 1;
+
+sub db {
+  my $self = shift;
+
+  return $self->{db} if $self->{db};
+
+  my $db = $self->{db} = $self->pg->db;
+  weaken $self;
+  $db->on(
+    notification => sub {
+      my ($db, $name, $pid, $payload) = @_;
+      $payload = eval { from_json $payload } if $self->{json}{$name};
+      my @cbs = @{$self->{chans}{$name}};
+      for my $cb (@cbs) { $self->$cb($payload) }
+    }
+  );
+
+  $db->once(close => sub { $self->emit(disconnect => delete $self->{db}) });
+  $db->listen($_) for keys %{$self->{chans}}, 'mojo.pubsub';
+  $self->emit(reconnect => $db);
+
+  return $db;
+}
 
 sub DESTROY { Mojo::Util::_global_destruction() or shift->reset }
 
@@ -12,12 +36,18 @@
 
 sub listen {
   my ($self, $name, $cb) = @_;
-  $self->_db->listen($name) unless @{$self->{chans}{$name} ||= []};
+  $self->db->listen($name) unless @{$self->{chans}{$name} ||= []};
   push @{$self->{chans}{$name}}, $cb;
   return $cb;
 }
 
-sub notify { $_[0]->_db->notify(_json(@_)) and return $_[0] }
+sub new {
+  my $self = shift->SUPER::new(@_);
+  $self->on(disconnect => \&_disconnect);
+  return $self;
+}
+
+sub notify { $_[0]->db->notify(_json(@_)) and return $_[0] }
 
 sub reset {
   my $self = shift;
@@ -30,30 +60,20 @@
   my ($self, $name, $cb) = @_;
   my $chan = $self->{chans}{$name};
   @$chan = $cb ? grep { $cb ne $_ } @$chan : ();
-  $self->_db->unlisten($name) and delete $self->{chans}{$name} unless @$chan;
+  $self->db->unlisten($name) and delete $self->{chans}{$name} unless @$chan;
   return $self;
 }
 
-sub _db {
+sub _disconnect {
   my $self = shift;
 
-  return $self->{db} if $self->{db};
-
-  my $db = $self->{db} = $self->pg->db;
   weaken $self;
-  $db->on(
-    notification => sub {
-      my ($db, $name, $pid, $payload) = @_;
-      $payload = eval { from_json $payload } if $self->{json}{$name};
-      my @cbs = @{$self->{chans}{$name}};
-      for my $cb (@cbs) { $self->$cb($payload) }
+  my $r;
+  $r = Mojo::IOLoop->recurring(
+    $self->reconnect_interval => sub {
+      Mojo::IOLoop->remove($r) if eval { $self->db };
     }
   );
-  $db->once(close => sub { $self->{pg} and $self->_db if delete $self->{db} });
-  $db->listen($_) for keys %{$self->{chans}}, 'mojo.pubsub';
-  $self->emit(reconnect => $db);
-
-  return $db;
 }
 
 sub _json { $_[1], $_[0]{json}{$_[1]} ? to_json $_[2] : $_[2] }
@@ -90,6 +110,15 @@
 L<Mojo::Pg::PubSub> inherits all events from L<Mojo::EventEmitter> and can
 emit the following new ones.
 
+=head2 disconnect
+
+  $pubsub->on(disconnect => sub {
+    my ($pubsub, $db) = @_;
+    ...
+  });
+
+Emitted after the current database connection is lost.
+
 =head2 reconnect
 
   $pubsub->on(reconnect => sub {
@@ -112,11 +141,29 @@
 L<Mojo::Pg> object this publish/subscribe container belongs to. Note that this
 attribute is weakened.
 
+=head2 reconnect_interval
+
+  my $interval = $pubsub->reconnect_interval;
+  $pubsub      = $pubsub->reconnect_interval(0.1);
+
+Amount of time in seconds to wait to reconnect after disconnecting, defaults to
+C<1>.
+
 =head1 METHODS
 
 L<Mojo::Pg::PubSub> inherits all methods from L<Mojo::EventEmitter> and
 implements the following new ones.
 
+=head2 db
+
+  my $db = $pubsub->db;
+
+Build and cache or get cached L<Mojo::Pg::Database> connection from L</"pg">.
+Used to reconnect if disconnected.
+
+  # Reconnect immediately
+  $pubsub->unsubscribe('disconnect')->on(disconnect => sub { shift->db });
+
 =head2 json
 
   $pubsub = $pubsub->json('foo');
@@ -149,6 +196,15 @@
     say "Two: $payload";
   });
 
+=head2 new
+
+  my $pubsub = Mojo::Pg::PubSub->new;
+  my $pubsub = Mojo::Pg::PubSub->new(pg => Mojo::Pg->new);
+  my $pubsub = Mojo::Pg::PubSub->new({pg => Mojo::Pg->new});
+
+Construct a new L<Mojo::Pg::PubSub> object and subscribe to the 
L</"disconnect">
+event with default reconnect logic.
+
 =head2 notify
 
   $pubsub = $pubsub->notify('foo');
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Mojo-Pg-4.11/lib/Mojo/Pg/Results.pm 
new/Mojo-Pg-4.12/lib/Mojo/Pg/Results.pm
--- old/Mojo-Pg-4.11/lib/Mojo/Pg/Results.pm     2018-05-08 13:42:43.000000000 
+0200
+++ new/Mojo-Pg-4.12/lib/Mojo/Pg/Results.pm     2018-11-22 21:26:38.000000000 
+0100
@@ -46,7 +46,7 @@
   my ($idx, $name) = @$self{qw(idx name)};
   unless ($idx) {
     my $types = $self->sth->{pg_type};
-    my @idx = grep { $types->[$_] eq 'json' || $types->[$_] eq 'jsonb' }
+    my @idx   = grep { $types->[$_] eq 'json' || $types->[$_] eq 'jsonb' }
       0 .. $#$types;
     ($idx, $name) = @$self{qw(idx name)} = (\@idx, [@{$self->columns}[@idx]]);
   }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Mojo-Pg-4.11/lib/Mojo/Pg.pm 
new/Mojo-Pg-4.12/lib/Mojo/Pg.pm
--- old/Mojo-Pg-4.11/lib/Mojo/Pg.pm     2018-10-18 01:11:55.000000000 +0200
+++ new/Mojo-Pg-4.12/lib/Mojo/Pg.pm     2018-11-24 18:03:33.000000000 +0100
@@ -34,7 +34,7 @@
 has [qw(password username)] => '';
 has pubsub => sub { Mojo::Pg::PubSub->new(pg => shift) };
 
-our $VERSION = '4.11';
+our $VERSION = '4.12';
 
 sub db { $_[0]->database_class->new(dbh => $_[0]->_prepare, pg => $_[0]) }
 
@@ -51,7 +51,7 @@
     unless $url->protocol =~ /^postgres(?:ql)?$/;
 
   # Connection information
-  my $db = $url->path->parts->[0];
+  my $db  = $url->path->parts->[0];
   my $dsn = defined $db ? "dbi:Pg:dbname=$db" : 'dbi:Pg:';
   if (my $host = $url->host) { $dsn .= ";host=$host" }
   if (my $port = $url->port) { $dsn .= ";port=$port" }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Mojo-Pg-4.11/t/crud.t new/Mojo-Pg-4.12/t/crud.t
--- old/Mojo-Pg-4.11/t/crud.t   2018-08-02 00:58:56.000000000 +0200
+++ new/Mojo-Pg-4.12/t/crud.t   2018-11-22 21:26:45.000000000 +0100
@@ -59,7 +59,7 @@
 is_deeply $result, [{id => 1, name => 'foo'}, {id => 2, name => 'baz'}],
   'right structure';
 $result = undef;
-$delay = Mojo::IOLoop->delay(sub { $result = pop->hashes->to_array });
+$delay  = Mojo::IOLoop->delay(sub { $result = pop->hashes->to_array });
 $db->select('crud_test', undef, undef, {-desc => 'id'}, $delay->begin);
 $delay->wait;
 is_deeply $result, [{id => 2, name => 'baz'}, {id => 1, name => 'foo'}],
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Mojo-Pg-4.11/t/database.t 
new/Mojo-Pg-4.12/t/database.t
--- old/Mojo-Pg-4.11/t/database.t       2018-02-19 00:54:41.000000000 +0100
+++ new/Mojo-Pg-4.12/t/database.t       2018-11-22 21:26:44.000000000 +0100
@@ -54,7 +54,7 @@
   },
   sub {
     my ($delay, $err_one, $one, $err_two, $two, $err_again, $again) = @_;
-    $fail = $err_one || $err_two || $err_again;
+    $fail   = $err_one || $err_two || $err_again;
     $result = [$one->hashes->first, $two->hashes->first, 
$again->hashes->first];
   }
 )->wait;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/Mojo-Pg-4.11/t/pubsub.t new/Mojo-Pg-4.12/t/pubsub.t
--- old/Mojo-Pg-4.11/t/pubsub.t 2018-02-19 00:54:40.000000000 +0100
+++ new/Mojo-Pg-4.12/t/pubsub.t 2018-11-24 12:32:24.000000000 +0100
@@ -104,8 +104,34 @@
   is_deeply \@test, ['works'], 'right messages';
 };
 
+# Reconnect while listening multiple retries
+$pg   = Mojo::Pg->new($ENV{TEST_ONLINE});
+@dbhs = @test = ();
+$pg->pubsub->reconnect_interval(0.1);
+$pg->pubsub->on(reconnect => sub { push @dbhs, pop->dbh });
+$pg->pubsub->listen(pstest => sub { push @test, pop });
+ok $dbhs[0], 'database handle';
+is_deeply \@test, [], 'no messages';
+{
+  local $dbhs[0]{Warn} = 0;
+  $pg->pubsub->on(
+    reconnect => sub { shift->notify(pstest => 'works'); Mojo::IOLoop->stop });
+  my $dsn = $pg->dsn;
+  $pg->pubsub->on(
+    disconnect => sub {
+      Mojo::IOLoop->timer(0.2 => sub { $pg->dsn($dsn) });
+    }
+  );
+  $pg->db->query('select pg_terminate_backend(?)', $dbhs[0]{pg_pid});
+  $pg->dsn('dbi:Pg:badoption=1');
+  Mojo::IOLoop->start;
+  ok $dbhs[1], 'database handle';
+  isnt $dbhs[0], $dbhs[1], 'different database handles';
+  is_deeply \@test, ['works'], 'right messages';
+};
+
 # Reconnect while not listening
-$pg = Mojo::Pg->new($ENV{TEST_ONLINE});
+$pg   = Mojo::Pg->new($ENV{TEST_ONLINE});
 @dbhs = @test = ();
 $pg->pubsub->on(reconnect => sub { push @dbhs, pop->dbh });
 $pg->pubsub->notify(pstest => 'fail');
@@ -124,7 +150,7 @@
 };
 
 # Reset
-$pg = Mojo::Pg->new($ENV{TEST_ONLINE});
+$pg   = Mojo::Pg->new($ENV{TEST_ONLINE});
 @dbhs = @test = ();
 $pg->pubsub->on(reconnect => sub { push @dbhs, pop->dbh });
 $pg->pubsub->listen(pstest => sub { push @test, pop });


Reply via email to