I do something like this in the MojoMySQL.pm plugin
-------

  $MOJOMYSQL = Mojo::mysql->new($URL);

        # See if the damned thing is up.
        # since we're in ::startup, we don't have the config plugin
available
        # ( we pass the config filename in as "app_config" )
        my $config = eval qx{cat $conf->{'app_config'}}
                or $log->logdie("Couldn't read config file: " .
$conf->{'app_config'});

    eval {
                local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
        alarm $config->{'db_ping_timeout'};
                my $ok = $MOJOMYSQL->db->ping();
        alarm 0;
        };

        if ($@) {
                $log->logdie($@) unless $@ eq "alarm\n";   # propagate
unexpected errors
                # timed out
                my $msg = qq{DB PING FAILED! (continued below)\n}
                                        . qq{****    It seems that
$conf->{'db'} on $conf->{'host'} is down!    ****\n}
                                        . qq{****    app runtime env is:
$config->{'environment'}    ****\n}
                                        . qq{****    Verify correct setting
in $conf->{'app_config'}    ****\n};

                $log->logdie($msg);
        }
        else {
                # didn't
                $log->debug("DB PING: $conf->{'db'} is up");
                return $MOJOMYSQL;
        };

} # sub mojomysql

On Thu, Oct 8, 2020 at 2:44 AM Nacho B <jib...@gmail.com> wrote:

> Hi, I am using Mojo::Pg  promises with db queries, and everything  is
> great.
>
> But I do not how to manage the case in which database server is down and
> no response is arriving.
>
> I presume that I should insert a timeout somewhere, in the promise, but I
> do not know how.
>
>
> Nacho B.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mojolicious+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mojolicious/0b90c0f5-3cb7-4647-8f5e-c1413b713725n%40googlegroups.com
> <https://groups.google.com/d/msgid/mojolicious/0b90c0f5-3cb7-4647-8f5e-c1413b713725n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CAG2_C8BsiwrPgAFVGaeuirrYaNWT83aMeZV2oDu6ECe0VHnDcg%40mail.gmail.com.

Reply via email to