]> Raphaƫl G. Git Repositories - airbundle/blobdiff - Command/CalendarCommand.php
Match constructor prototype
[airbundle] / Command / CalendarCommand.php
index f722aaed4cfa842eeb2bf74cedd6ee93a68ea99f..005c0a8f78917ba24a1f3b3af5c5f8d866f71766 100644 (file)
@@ -136,6 +136,7 @@ class CalendarCommand extends Command {
                        //With expired token
                        if ($this->google->isAccessTokenExpired()) {
                                //Refresh token
+                               //TODO: better handle internal_failure
                                if (($gRefresh = $this->google->getRefreshToken()) && ($gToken = $this->google->fetchAccessTokenWithRefreshToken($gRefresh)) && empty($gToken['error'])) {
                                        //Get google token
                                        $googleToken = $this->doctrine->getRepository(GoogleToken::class)->findOneById($token['id']);
@@ -157,6 +158,7 @@ class CalendarCommand extends Command {
                                //Refresh failed
                                } else {
                                        //Show error
+                                       //TODO: remove that and simply log internal failure ?
                                        fprintf(STDERR, 'Unable to refresh token %d: %s', $token['id'], $gToken['error']?:'');
 
                                        //TODO: warn user by mail ?
@@ -288,6 +290,9 @@ class CalendarCommand extends Command {
                                                }
                                        //Catch exception
                                        } catch(\Google\Service\Exception $e) {
+                                               //Sleep
+                                               usleep(500000);
+
                                                //Identifier already exists
                                                if ($e->getCode() == 409) {
                                                        //Get calendar event
@@ -305,10 +310,19 @@ class CalendarCommand extends Command {
                                                //TODO: handle other codes gracefully ? (503 & co)
                                                //Other errors
                                                } else {
+                                                       //XXX: with a 400 code and too low sequence number, it may be solved by reseting cache key
+                                                       #"reason": "invalid",
+                                                       #"message": "Invalid sequence value. The specified sequence number is be
+                                                       #low the current sequence number of the resource. Re-fetch the resource and
+                                                       #use its sequence number on the following request."
+                                                       #$this->cache->delete($cacheKey);
                                                        //Throw error
                                                        throw new \LogicException(sprintf('Calendar %s event %s operation failed', $calendar, $this->prefix.$session['id']), 0, $e);
                                                }
                                        }
+
+                                       //Sleep
+                                       usleep(500000);
                                }
 
                                //Get all sessions
@@ -334,6 +348,9 @@ class CalendarCommand extends Command {
                                                        //Drop from events array
                                                        unset($events[$sid]);
                                                }
+
+                                               //Sleep
+                                               usleep(500000);
                                        }
                                }