Skip to content

Commit 419c94d

Browse files
mstovicekmaxbanton
authored andcommitted
Refresh with fresh sequence token (#56)
* Refresh with fresh sequence token * reformats phpdoc to fit within 140 characters
1 parent 4034b71 commit 419c94d

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/Handler/CloudWatch.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,17 @@ private function addToBuffer(array $record)
167167
private function flushBuffer()
168168
{
169169
if (!empty($this->buffer)) {
170-
// send items
171-
$this->send($this->buffer);
170+
// send items, retry once with a fresh sequence token
171+
try {
172+
$this->send($this->buffer);
173+
} catch (\Aws\CloudWatchLogs\Exception\CloudWatchLogsException $e) {
174+
$this->refreshSequenceToken();
175+
$this->send($this->buffer);
176+
}
177+
172178
// clear buffer
173179
$this->buffer = [];
180+
174181
// clear data amount
175182
$this->currentDataAmount = 0;
176183
}
@@ -240,6 +247,9 @@ private function formatRecords(array $entry)
240247
* - A batch of log events in a single request cannot span more than 24 hours. Otherwise, the operation fails.
241248
*
242249
* @param array $entries
250+
*
251+
* @throws \Aws\CloudWatchLogs\Exception\CloudWatchLogsException Thrown by putLogEvents for example in case of an
252+
* invalid sequence token
243253
*/
244254
private function send(array $entries)
245255
{
@@ -305,6 +315,13 @@ function ($group) {
305315
}
306316
}
307317

318+
$this->refreshSequenceToken();
319+
320+
$this->initialized = true;
321+
}
322+
323+
private function refreshSequenceToken()
324+
{
308325
// fetch existing streams
309326
$existingStreams =
310327
$this

0 commit comments

Comments
 (0)