diff options
author | Daniel Friesel <derf@finalrewind.org> | 2022-05-27 12:04:51 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2022-05-27 12:04:51 +0200 |
commit | 7f8e7a1a5f1438d8c1ff889538268ba196e916c9 (patch) | |
tree | 3a86b0528569597c389da6e5b21f10b233dba35c | |
parent | 3468e2ef36f968d58cf1e1107e7974aae1067c9b (diff) |
limit number of concurrent traewelling requests to five per second1.22.4
-rw-r--r-- | lib/Travelynx/Command/work.pm | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/Travelynx/Command/work.pm b/lib/Travelynx/Command/work.pm index 706eb44..b0458db 100644 --- a/lib/Travelynx/Command/work.pm +++ b/lib/Travelynx/Command/work.pm @@ -4,6 +4,7 @@ package Travelynx::Command::work; # # SPDX-License-Identifier: AGPL-3.0-or-later use Mojo::Base 'Mojolicious::Command'; +use Mojo::Promise; use DateTime; use JSON; @@ -197,15 +198,22 @@ sub run { trip_id => $trip_id ); } + my $request_count = 0; for my $account_data ( $self->app->traewelling->get_pull_accounts ) { # $account_data->{user_id} is the travelynx uid # $account_data->{user_name} is the Träwelling username + $request_count += 1; $self->app->log->debug( - "Pulling Traewelling status for UID $account_data->{user_id}"); - $self->app->traewelling_api->get_status_p( - username => $account_data->{data}{user_name}, - token => $account_data->{token} +"Scheduling Traewelling status pull for UID $account_data->{user_id}" + ); + Mojo::Promise->timer( $request_count * 0.2 )->then( + sub { + return $self->app->traewelling_api->get_status_p( + username => $account_data->{data}{user_name}, + token => $account_data->{token} + ); + } )->then( sub { my ($traewelling) = @_; |