summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-03-26 19:05:38 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2025-03-26 19:05:38 +0100
commit3dbdefa8bdfb7029bb8c508f148554fd4fa6038d (patch)
tree4c6f13a1fd9b5d09dd17d605158671e486eb594b
parent67d1cf52674102da4edb87a874f033a3124fc5c6 (diff)
work: decrease bahn.de request frequency; detect rate limiting2.11.5
-rw-r--r--lib/Travelynx/Command/work.pm15
1 files changed, 13 insertions, 2 deletions
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;