From 918ed6ab1f25d0babb2cfa6051ed7b49c58c3834 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Thu, 30 May 2024 11:54:02 +0200 Subject: DBDB: Add some debug statements --- lib/Travelynx/Helper/DBDB.pm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lib/Travelynx/Helper') 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; -- cgit v1.2.3