adjust(); } } public function adjust() { Account::query()->cursor()->each(function ($account) { nlog("resetting email quota for {$account->key}"); $email_count = Cache::get("email_quota".$account->key); if ($email_count > 0) { try { LightLogs::create(new EmailCount($email_count, $account->key))->send(); // this runs syncronously } catch(\Exception $e) { nlog("Exception:: AdjustEmailQuota::" . $e->getMessage()); nlog($e->getMessage()); } } }); /** Use redis pipelines to execute bulk deletes efficiently */ $redis = Redis::connection('sentinel-cache'); $prefix = config('cache.prefix'). "email_quota*"; $keys = $redis->keys($prefix); if (is_array($keys)) { $redis->pipeline(function ($pipe) use ($keys) { foreach ($keys as $key) { $pipe->del($key); } }); } $keys = null; $prefix = config('cache.prefix'). "throttle_notified*"; $keys = $redis->keys($prefix); if (is_array($keys)) { $redis->pipeline(function ($pipe) use ($keys) { foreach ($keys as $key) { $pipe->del($key); } }); } } }