DBDB: Add some debug statements
This commit is contained in:
parent
9442572084
commit
918ed6ab1f
1 changed files with 23 additions and 0 deletions
|
@ -36,9 +36,13 @@ sub has_wagonorder_p {
|
||||||
|
|
||||||
if ( my $content = $cache->get("HEAD $url") ) {
|
if ( my $content = $cache->get("HEAD $url") ) {
|
||||||
if ( $content eq 'n' ) {
|
if ( $content eq 'n' ) {
|
||||||
|
$self->{log}
|
||||||
|
->debug("has_wagonorder_p(${train_no}/${api_ts}): n (cached)");
|
||||||
return $promise->reject;
|
return $promise->reject;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
$self->{log}
|
||||||
|
->debug("has_wagonorder_p(${train_no}/${api_ts}): y (cached)");
|
||||||
return $promise->resolve($content);
|
return $promise->resolve($content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,10 +52,14 @@ sub has_wagonorder_p {
|
||||||
sub {
|
sub {
|
||||||
my ($tx) = @_;
|
my ($tx) = @_;
|
||||||
if ( $tx->result->is_success ) {
|
if ( $tx->result->is_success ) {
|
||||||
|
$self->{log}
|
||||||
|
->debug("has_wagonorder_p(${train_no}/${api_ts}): a");
|
||||||
$cache->set( "HEAD $url", 'a' );
|
$cache->set( "HEAD $url", 'a' );
|
||||||
$promise->resolve('a');
|
$promise->resolve('a');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
$self->{log}
|
||||||
|
->debug("has_wagonorder_p(${train_no}/${api_ts}): n");
|
||||||
$cache->set( "HEAD $url", 'n' );
|
$cache->set( "HEAD $url", 'n' );
|
||||||
$promise->reject;
|
$promise->reject;
|
||||||
}
|
}
|
||||||
|
@ -59,6 +67,7 @@ sub has_wagonorder_p {
|
||||||
}
|
}
|
||||||
)->catch(
|
)->catch(
|
||||||
sub {
|
sub {
|
||||||
|
$self->{log}->debug("has_wagonorder_p(${train_no}/${api_ts}): n");
|
||||||
$cache->set( "HEAD $url", 'n' );
|
$cache->set( "HEAD $url", 'n' );
|
||||||
$promise->reject;
|
$promise->reject;
|
||||||
return;
|
return;
|
||||||
|
@ -77,6 +86,8 @@ sub get_wagonorder_p {
|
||||||
my $promise = Mojo::Promise->new;
|
my $promise = Mojo::Promise->new;
|
||||||
|
|
||||||
if ( my $content = $cache->thaw($url) ) {
|
if ( my $content = $cache->thaw($url) ) {
|
||||||
|
$self->{log}
|
||||||
|
->debug("get_wagonorder_p(${train_no}/${api_ts}): (cached)");
|
||||||
$promise->resolve($content);
|
$promise->resolve($content);
|
||||||
return $promise;
|
return $promise;
|
||||||
}
|
}
|
||||||
|
@ -89,11 +100,15 @@ sub get_wagonorder_p {
|
||||||
if ( $tx->result->is_success ) {
|
if ( $tx->result->is_success ) {
|
||||||
my $body = decode( 'utf-8', $tx->res->body );
|
my $body = decode( 'utf-8', $tx->res->body );
|
||||||
my $json = JSON->new->decode($body);
|
my $json = JSON->new->decode($body);
|
||||||
|
$self->{log}
|
||||||
|
->debug("get_wagonorder_p(${train_no}/${api_ts}): success");
|
||||||
$cache->freeze( $url, $json );
|
$cache->freeze( $url, $json );
|
||||||
$promise->resolve($json);
|
$promise->resolve($json);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
my $code = $tx->code;
|
my $code = $tx->code;
|
||||||
|
$self->{log}->debug(
|
||||||
|
"get_wagonorder_p(${train_no}/${api_ts}): HTTP ${code}");
|
||||||
$promise->reject("HTTP ${code}");
|
$promise->reject("HTTP ${code}");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -101,6 +116,8 @@ sub get_wagonorder_p {
|
||||||
)->catch(
|
)->catch(
|
||||||
sub {
|
sub {
|
||||||
my ($err) = @_;
|
my ($err) = @_;
|
||||||
|
$self->{log}
|
||||||
|
->debug("get_wagonorder_p(${train_no}/${api_ts}): error ${err}");
|
||||||
$promise->reject($err);
|
$promise->reject($err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -117,6 +134,7 @@ sub get_stationinfo_p {
|
||||||
my $promise = Mojo::Promise->new;
|
my $promise = Mojo::Promise->new;
|
||||||
|
|
||||||
if ( my $content = $cache->thaw($url) ) {
|
if ( my $content = $cache->thaw($url) ) {
|
||||||
|
$self->{log}->debug("get_stationinfo_p(${eva}): (cached)");
|
||||||
return $promise->resolve($content);
|
return $promise->resolve($content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,12 +144,16 @@ sub get_stationinfo_p {
|
||||||
my ($tx) = @_;
|
my ($tx) = @_;
|
||||||
|
|
||||||
if ( my $err = $tx->error ) {
|
if ( my $err = $tx->error ) {
|
||||||
|
$self->{log}->debug(
|
||||||
|
"get_stationinfo_p(${eva}): HTTP $err->{code} $err->{message}"
|
||||||
|
);
|
||||||
$cache->freeze( $url, {} );
|
$cache->freeze( $url, {} );
|
||||||
$promise->reject("HTTP $err->{code} $err->{message}");
|
$promise->reject("HTTP $err->{code} $err->{message}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $json = $tx->result->json;
|
my $json = $tx->result->json;
|
||||||
|
$self->{log}->debug("get_stationinfo_p(${eva}): success");
|
||||||
$cache->freeze( $url, $json );
|
$cache->freeze( $url, $json );
|
||||||
$promise->resolve($json);
|
$promise->resolve($json);
|
||||||
return;
|
return;
|
||||||
|
@ -139,6 +161,7 @@ sub get_stationinfo_p {
|
||||||
)->catch(
|
)->catch(
|
||||||
sub {
|
sub {
|
||||||
my ($err) = @_;
|
my ($err) = @_;
|
||||||
|
$self->{log}->debug("get_stationinfo_p(${eva}): Error ${err}");
|
||||||
$cache->freeze( $url, {} );
|
$cache->freeze( $url, {} );
|
||||||
$promise->reject($err);
|
$promise->reject($err);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue