summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-05-30 11:54:02 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2024-05-30 11:54:02 +0200
commit918ed6ab1f25d0babb2cfa6051ed7b49c58c3834 (patch)
treef403871e7307644e91697eea5f6dcac412e39fef /lib
parent9442572084f93492e5586171a86974513faa4e36 (diff)
DBDB: Add some debug statements
Diffstat (limited to 'lib')
-rw-r--r--lib/Travelynx/Helper/DBDB.pm23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/Travelynx/Helper/DBDB.pm b/lib/Travelynx/Helper/DBDB.pm
index 8dc3e36..da3bfb1 100644
--- a/lib/Travelynx/Helper/DBDB.pm
+++ b/lib/Travelynx/Helper/DBDB.pm
@@ -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);
}
}
@@ -48,10 +52,14 @@ 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;
}
@@ -59,6 +67,7 @@ sub has_wagonorder_p {
}
)->catch(
sub {
+ $self->{log}->debug("has_wagonorder_p(${train_no}/${api_ts}): n");
$cache->set( "HEAD $url", 'n' );
$promise->reject;
return;
@@ -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;
}
@@ -89,11 +100,15 @@ 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;
@@ -101,6 +116,8 @@ sub get_wagonorder_p {
)->catch(
sub {
my ($err) = @_;
+ $self->{log}
+ ->debug("get_wagonorder_p(${train_no}/${api_ts}): error ${err}");
$promise->reject($err);
return;
}
@@ -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);
}
@@ -126,12 +144,16 @@ 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;
@@ -139,6 +161,7 @@ sub get_stationinfo_p {
)->catch(
sub {
my ($err) = @_;
+ $self->{log}->debug("get_stationinfo_p(${eva}): Error ${err}");
$cache->freeze( $url, {} );
$promise->reject($err);
return;