/**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     set_time_limit(0);
     ini_set('memory_limit', '2048M');
     //Create the Duo Admin Client and set the timeout higher than default
     $duoAdmin = new DuoAdmin();
     $duoAdmin->setRequesterOption('timeout', '6000000');
     // Set the log $count value to 1000
     $count = 1000;
     $backoff = NULL;
     while ($count >= 1000) {
         \Log::debug('Start Log gathering', ['count' => $count, 'backoff' => $backoff]);
         //Query Duo REST API
         $response = $duoAdmin->logs($this->getMinTime());
         if (isset($response['response']['code']) && $response['response']['code'] == '42901') {
             $backoff += 10;
             \Log::debug('Received backoff notice', ['response' => $response, 'set-backoff' => $backoff]);
             sleep($backoff);
             continue;
         }
         //Duo SDK puts results in nested array [response][response]
         $logs = $response['response']['response'];
         $backoff = NULL;
         \Log::debug('Received Duo Response Object.  Adding new entries ', ['object-count' => count($logs), 'set-backoff' => $backoff]);
         // Loop each log to save
         foreach ($logs as $log) {
             // Get the DuoUser ID to create a relation
             $duoUserId = User::where('username', $log['username'])->first();
             // Sometimes the 'username' from Duo doesn't exist locally....
             if ($duoUserId) {
                 $log['duo_user_id'] = $duoUserId->id;
             } else {
                 $log['duo_user_id'] = NULL;
             }
             // Save the log
             Log::create($log);
         }
         // Set the count to number of logs returned in the last call.
         // If it's less than 1000, we've reached the end of the logs
         \Log::debug('Added new log entries.  Setting count: ', ['count' => count($logs)]);
         $count = count($logs);
     }
 }