Unverified Commit 3dbdefa8 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

work: decrease bahn.de request frequency; detect rate limiting

parent 67d1cf52
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ sub run {
	}

	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;