diff options
author | Daniel Friesel <derf@finalrewind.org> | 2023-01-07 13:31:14 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2023-01-07 13:31:14 +0100 |
commit | 61b91fe4b266e3c7984d37ccad3e21380372b921 (patch) | |
tree | 92cdd4fc250d327954e3291525661dd23272cecb /lib/Travelynx/Command/traewelling.pm | |
parent | 628bd319d627e94b0349391c2abce44fb51cab84 (diff) |
log traewelling sync HTTP status to influxdb1.29.6
Diffstat (limited to 'lib/Travelynx/Command/traewelling.pm')
-rw-r--r-- | lib/Travelynx/Command/traewelling.pm | 66 |
1 files changed, 60 insertions, 6 deletions
diff --git a/lib/Travelynx/Command/traewelling.pm b/lib/Travelynx/Command/traewelling.pm index d8eeaef..a586028 100644 --- a/lib/Travelynx/Command/traewelling.pm +++ b/lib/Travelynx/Command/traewelling.pm @@ -16,6 +16,7 @@ has usage => sub { shift->extract_usage }; sub pull_sync { my ($self) = @_; + my %pull_result; my $request_count = 0; for my $account_data ( $self->app->traewelling->get_pull_accounts ) { @@ -48,6 +49,7 @@ sub pull_sync { )->then( sub { my ($traewelling) = @_; + $pull_result{ $traewelling->{http} } += 1; $self->app->traewelling_to_travelynx( traewelling => $traewelling, user_data => $account_data @@ -56,19 +58,23 @@ sub pull_sync { )->catch( sub { my ($err) = @_; + $pull_result{ $err->{http} // 0 } += 1; $self->app->traewelling->log( uid => $account_data->{user_id}, - message => "Fehler bei der Status-Abfrage: $err", + message => "Fehler bei der Status-Abfrage: $err->{text}", is_error => 1 ); - $self->app->log->debug("Error $err"); + $self->app->log->debug("Error $err->{text}"); } )->wait; } + + return \%pull_result; } sub push_sync { my ($self) = @_; + my %push_result; for my $candidate ( $self->app->traewelling->get_pushable_accounts ) { $self->app->log->debug( @@ -90,9 +96,21 @@ sub push_sync { $self->app->log->debug("... already handled"); next; } - $self->app->traewelling_api->checkin( %{$candidate}, - trip_id => $trip_id ); + $self->app->traewelling_api->checkin_p( %{$candidate}, + trip_id => $trip_id )->then( + sub { + my ($status) = @_; + $push_result{ $status->{http} } += 1; + } + )->catch( + sub { + my ($status) = @_; + $push_result{ $status->{http} // 0 } += 1; + } + )->wait; } + + return \%push_result; } sub run { @@ -100,15 +118,17 @@ sub run { my $now = DateTime->now( time_zone => 'Europe/Berlin' ); my $started_at = $now; + my $push_result; + my $pull_result; if ( not $direction or $direction eq 'push' ) { - $self->push_sync; + $push_result = $self->push_sync; } my $trwl_push_finished_at = DateTime->now( time_zone => 'Europe/Berlin' ); if ( not $direction or $direction eq 'pull' ) { - $self->pull_sync; + $pull_result = $self->pull_sync; } my $trwl_pull_finished_at = DateTime->now( time_zone => 'Europe/Berlin' ); @@ -135,6 +155,40 @@ sub run { $self->app->ua->post_p( $self->app->config->{influxdb}->{url}, "traewelling ${report}" )->wait; } + + if ($push_result) { + for my $status ( keys %{$push_result} ) { + my $count = $push_result->{$status}; + if ( $self->app->mode eq 'development' ) { + $self->app->log->debug( 'POST ' + . $self->app->config->{influxdb}->{url} + . " traewelling_push,http=$status count=$count" ); + } + else { + $self->app->ua->post_p( + $self->app->config->{influxdb}->{url}, + "traewelling_push,http=$status count=$count" + )->wait; + } + } + } + + if ($pull_result) { + for my $status ( keys %{$pull_result} ) { + my $count = $pull_result->{$status}; + if ( $self->app->mode eq 'development' ) { + $self->app->log->debug( 'POST ' + . $self->app->config->{influxdb}->{url} + . " traewelling_pull,http=$status count=$count" ); + } + else { + $self->app->ua->post_p( + $self->app->config->{influxdb}->{url}, + "traewelling_pull,http=$status count=$count" + )->wait; + } + } + } } } |