Skip to content

Commit

Permalink
DBDB: Add some debug statements
Browse files Browse the repository at this point in the history
  • Loading branch information
derf committed May 30, 2024
1 parent 9442572 commit 918ed6a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/Travelynx/Helper/DBDB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ sub has_wagonorder_p {

if ( my $content = $cache->get("HEAD $url") ) {
if ( $content eq 'n' ) {
$self->{log}
->debug("has_wagonorder_p(${train_no}/${api_ts}): n (cached)");
return $promise->reject;
}
else {
$self->{log}
->debug("has_wagonorder_p(${train_no}/${api_ts}): y (cached)");
return $promise->resolve($content);
}
}
Expand All @@ -48,17 +52,22 @@ sub has_wagonorder_p {
sub {
my ($tx) = @_;
if ( $tx->result->is_success ) {
$self->{log}
->debug("has_wagonorder_p(${train_no}/${api_ts}): a");
$cache->set( "HEAD $url", 'a' );
$promise->resolve('a');
}
else {
$self->{log}
->debug("has_wagonorder_p(${train_no}/${api_ts}): n");
$cache->set( "HEAD $url", 'n' );
$promise->reject;
}
return;
}
)->catch(
sub {
$self->{log}->debug("has_wagonorder_p(${train_no}/${api_ts}): n");
$cache->set( "HEAD $url", 'n' );
$promise->reject;
return;
Expand All @@ -77,6 +86,8 @@ sub get_wagonorder_p {
my $promise = Mojo::Promise->new;

if ( my $content = $cache->thaw($url) ) {
$self->{log}
->debug("get_wagonorder_p(${train_no}/${api_ts}): (cached)");
$promise->resolve($content);
return $promise;
}
Expand All @@ -89,18 +100,24 @@ sub get_wagonorder_p {
if ( $tx->result->is_success ) {
my $body = decode( 'utf-8', $tx->res->body );
my $json = JSON->new->decode($body);
$self->{log}
->debug("get_wagonorder_p(${train_no}/${api_ts}): success");
$cache->freeze( $url, $json );
$promise->resolve($json);
}
else {
my $code = $tx->code;
$self->{log}->debug(
"get_wagonorder_p(${train_no}/${api_ts}): HTTP ${code}");
$promise->reject("HTTP ${code}");
}
return;
}
)->catch(
sub {
my ($err) = @_;
$self->{log}
->debug("get_wagonorder_p(${train_no}/${api_ts}): error ${err}");
$promise->reject($err);
return;
}
Expand All @@ -117,6 +134,7 @@ sub get_stationinfo_p {
my $promise = Mojo::Promise->new;

if ( my $content = $cache->thaw($url) ) {
$self->{log}->debug("get_stationinfo_p(${eva}): (cached)");
return $promise->resolve($content);
}

Expand All @@ -126,19 +144,24 @@ sub get_stationinfo_p {
my ($tx) = @_;

if ( my $err = $tx->error ) {
$self->{log}->debug(
"get_stationinfo_p(${eva}): HTTP $err->{code} $err->{message}"
);
$cache->freeze( $url, {} );
$promise->reject("HTTP $err->{code} $err->{message}");
return;
}

my $json = $tx->result->json;
$self->{log}->debug("get_stationinfo_p(${eva}): success");
$cache->freeze( $url, $json );
$promise->resolve($json);
return;
}
)->catch(
sub {
my ($err) = @_;
$self->{log}->debug("get_stationinfo_p(${eva}): Error ${err}");
$cache->freeze( $url, {} );
$promise->reject($err);
return;
Expand Down

0 comments on commit 918ed6a

Please sign in to comment.