From 3dbdefa8bdfb7029bb8c508f148554fd4fa6038d Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Wed, 26 Mar 2025 19:05:38 +0100 Subject: work: decrease bahn.de request frequency; detect rate limiting --- lib/Travelynx/Command/work.pm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/Travelynx/Command/work.pm b/lib/Travelynx/Command/work.pm index e131533..143812d 100644 --- a/lib/Travelynx/Command/work.pm +++ b/lib/Travelynx/Command/work.pm @@ -35,7 +35,8 @@ sub run { $self->app->log->debug("Removed ${num_incomplete} incomplete checkins"); } - my $errors = 0; + my $errors = 0; + my $dbris_rate_limited = 0; for my $entry ( $self->app->in_transit->get_all_active ) { @@ -53,10 +54,17 @@ sub run { eval { - $self->app->dbris->get_journey_p( trip_id => $train_id )->then( + Mojo::Promise->timer( $dbris_rate_limited ? 2.5 : 0.5 )->then( + sub { + return $self->app->dbris->get_journey_p( + trip_id => $train_id ); + } + )->then( sub { my ($journey) = @_; + $dbris_rate_limited = 0; + my $found_dep; my $found_arr; for my $stop ( $journey->route ) { @@ -131,6 +139,9 @@ sub run { $self->app->log->error( "work($uid) @ DBRIS $entry->{backend_name}: journey: $err" ); + if ( $err =~ m{HTTP 429} ) { + $dbris_rate_limited = 1; + } } )->wait; -- cgit v1.2.3