Skip to content

Commit 6c97d78

Browse files
ISSUE-84: Another try at rate limit fix
1 parent 2cde6ad commit 6c97d78

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/Domain/Strava/Activity/Stream/ImportActivityStreams/ImportActivityStreamsCommandHandler.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,28 @@ public function handle(Command $command): void
3434
continue;
3535
}
3636

37+
$stravaStreams = [];
3738
try {
3839
$stravaStreams = $this->strava->getAllActivityStreams($activityId);
40+
// Try to avoid Strava rate limits.
41+
$this->sleep->sweetDreams(10);
3942
} catch (ClientException|RequestException $exception) {
4043
if (!$exception->getResponse()) {
4144
// Re-throw, we only want to catch supported error codes.
4245
throw $exception;
4346
}
4447

45-
if (404 === $exception->getResponse()->getStatusCode()) {
46-
// Try to avoid Strava rate limits.
47-
$this->sleep->sweetDreams(10);
48-
// Skip.
49-
continue;
50-
}
51-
5248
if (429 === $exception->getResponse()->getStatusCode()) {
5349
// This will allow initial imports with a lot of activities to proceed the next day.
5450
// This occurs when we exceed Strava API rate limits or throws an unexpected error.
5551
$command->getOutput()->writeln('<error>You probably reached Strava API rate limits. You will need to import the rest of your activities tomorrow</error>');
5652
break;
5753
}
5854

59-
$command->getOutput()->writeln(sprintf('<error>Strava API threw error: %s</error>', $exception->getMessage()));
60-
break;
55+
if (404 !== $exception->getResponse()->getStatusCode()) {
56+
$command->getOutput()->writeln(sprintf('<error>Strava API threw error: %s</error>', $exception->getMessage()));
57+
break;
58+
}
6159
}
6260

6361
$stravaStreams = array_filter(
@@ -88,9 +86,6 @@ public function handle(Command $command): void
8886
$this->activityStreamRepository->add($stream);
8987
$command->getOutput()->writeln(sprintf(' => Imported activity stream "%s"', $stream->getName()));
9088
}
91-
92-
// Try to avoid Strava rate limits.
93-
$this->sleep->sweetDreams(10);
9489
}
9590
}
9691
}

tests/strava.db

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)