public function provision(Request $request, $id, $uuid) { $provision = \App\Provision::where('id', $id)->where('uuid', $uuid)->first(); if ($provision === null) { $request->session()->flash(str_random(4), ['type' => 'danger', 'message' => 'Could not find id/uuid combo']); return redirect('/?ohno'); } $redisKey = config('rediskeys.digitalocean_token') . $uuid; Redis::set($redisKey, $request->session()->get('digitalocean')['token']); // This expire is a backup in case the provision job fails, and doesn't delete the key explicitly at the end Redis::expire($redisKey, 60 * 60); // 60 minutes - if a provision job takes longer than this we won't be able to delete our SSH keys from the users DO account $provision->inputs = $request->session()->get("inputs.{$uuid}"); // It doesn't accept SSH connections immediately after creation, so we delay $job = (new \App\Jobs\Provision($provision))->delay(5); $this->dispatch($job); return redirect(url('/provision/provisioning/' . $provision->id . '/' . $provision->uuid)); }
private static function requestRecentJobsCache() { $jobs = DB::table('jobs')->select('id', 'updated_at')->orderBy('updated_at', 'desc')->take(1000)->get(); if (!empty($jobs)) { $cache_key = self::getRecentJobsCacheKey(); foreach ($jobs as $job) { Redis::zadd($cache_key, strtotime($job->updated_at), $job->id); } Redis::expire($cache_key, 60 * 60 * 24 * 1); } }
private static function requestDmaListCache($str) { $cache_key = self::getDmaListCacheKey($str); $map = self::where('city_state', 'like', $str . '%')->select('code', 'city_state')->orderBy('city_state', 'asc')->take(20)->get(); if (!empty($map)) { $i = 1; foreach ($map as $record) { $location_record = ['region' => $record->city_state, 'code' => $record->code]; Redis::zadd($cache_key, $i, json_encode($location_record)); $i++; } } else { // set an empty values to reduce db hit Redis::zadd($cache_key, $i, json_encode([])); } Redis::expire($cache_key, 60 * 60 * 24 * 7); }