/** * Show the application welcome screen to the user. * * Here we grab all the ”harvests” from the `harvests` table * and use the data within to run the jobs to update. * * @return Response */ public function index() { $harvests = Harvest::orderBy('resource', 'asc')->orderBy('action', 'asc')->get(); $harvestsGroupedByResource = $harvests->groupBy('resource'); $resources = $harvests->unique('resource'); return view('dashboard', ['harvests' => $harvestsGroupedByResource, 'resources' => $resources]); }
/** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * * @return void */ protected function schedule(Schedule $schedule) { /** * Create the schedule based upon what is in the `harvests` table */ try { $harvests = Harvest::all(); foreach ($harvests as $harvest) { /** * Both ping_before_url and then_ping_url could be NULL * in the database but things will fail silently if NULL * is passed to pingBefore() or thenPing(). * * This still assumes that if there is a value that it * is both valid and GET-able. If either is not a valid * URL or that URL does not return a response a silent * failure could still occur. */ if ($harvest->ping_before_url !== null && $harvest->then_ping_url !== null) { $schedule->command('harvest:update ' . $harvest->resource . ' --action=' . $harvest->action)->{$harvest->scheduler_frequency_method}()->withoutOverlapping()->pingBefore($harvest->ping_before_url)->thenPing($harvest->then_ping_url); } elseif ($harvest->ping_before_url !== null && $harvest->then_ping_url === null) { $schedule->command('harvest:update ' . $harvest->resource . ' --action=' . $harvest->action)->{$harvest->scheduler_frequency_method}()->withoutOverlapping()->pingBefore($harvest->ping_before_url); } elseif ($harvest->ping_before_url === null && $harvest->then_ping_url !== null) { $schedule->command('harvest:update ' . $harvest->resource . ' --action=' . $harvest->action)->{$harvest->scheduler_frequency_method}()->withoutOverlapping()->thenPing($harvest->then_ping_url); } else { // Both are null $schedule->command('harvest:update ' . $harvest->resource . ' --action=' . $harvest->action)->{$harvest->scheduler_frequency_method}()->withoutOverlapping(); } } } catch (\Exception $e) { // Hopefully we are only here because we are migrating, // which does not like the database query above. } }
/** * Execute the console command. * * @return mixed */ public function handle() { $harvests = Harvest::orderBy('resource', 'asc')->orderBy('action', 'asc')->get(['resource', 'action', 'last_run_at']); foreach ($harvests as $harvest) { $lastRunAt = 'Not yet run'; if ($harvest->last_run_at != null) { $lastRunAt = $harvest->last_run_at . ' (' . $harvest->last_run_at->diffForHumans() . ')'; } $data[] = [$harvest->resource, $harvest->action, $lastRunAt]; } $headers = ['Resource', 'Action', 'Last Run']; $this->table($headers, $data); }
/** * Execute the console command. * * @return mixed */ public function handle() { $resource = $this->argument('resource'); $action = $this->option('action'); $startPage = (int) $this->option('startPage'); $perPage = (int) $this->option('perPage'); try { $harvest = Harvest::where('resource', $resource)->where('action', $action)->firstOrFail(); } catch (\Exception $e) { $this->info('There is no existing action for updating ' . ucwords($action) . ' ' . ucwords($resource) . '.'); exit('Nothing was updated.'); } $options = ['startPage' => $startPage, 'perPage' => $perPage, 'lastRun' => new Carbon('2001-01-01')]; $job = new UpdateResourceJob($harvest, $options); $message = 'Fully refreshing ' . $action . ' ' . $resource . ' ' . $perPage . ' at a time'; if (isset($lastRun)) { $message .= ' with entries updated since ' . $lastRun->format('r'); } $this->info($message); $this->dispatch($job); }
/** * @return \Illuminate\View\View */ public function performersPopularity() { try { $harvest = Harvest::where('resource', 'performers')->where('action', 'popularity')->firstOrFail(); } catch (\Exception $e) { abort(404, 'There is no existing action for updating Performers Popularity.'); } /** * Get all the categories and then loop through them creating an * UpdatePerformerPopularityJob for each one. */ try { $categories = Category::active()->orderBy('id')->get(); } catch (\Exception $e) { abort(404, 'There are no categories yet. Please ensure you have run the Active Categories job.'); } // Get the last category->id so we can later detect that the Job for that // category->id has completed in order to know to fire the ResourceUpdateWasCompleted Event $last_category_id = $categories->last()->id; foreach ($categories as $category) { $job = new UpdatePerformerPopularityJob($harvest, $category->id, $last_category_id); $this->dispatch($job); } return view('resource', ['pageTitle' => 'Performers | Popularity | TEvo Harvester', 'job' => $job]); }
/** * Execute the console command. * * @return mixed */ protected function handlePopularity() { $resource = 'performers'; $action = 'popularity'; try { $harvest = Harvest::where('resource', $resource)->where('action', $action)->firstOrFail(); } catch (\Exception $e) { $this->info('There is no existing action for updating ' . ucwords($action) . ' ' . ucwords($resource) . '.'); exit('Nothing was updated.'); } /** * Get all the categories and then loop through them creating an * UpdatePerformerPopularityJob for each one. */ try { $categories = Category::active()->orderBy('id')->get(); } catch (\Exception $e) { abort(404, 'There are no categories yet. Please ensure you have run the Active Categories job.'); } $message = 'Updating the popularity_score for the 100 most popular Performers in each Category.'; $this->info($message); // Get the last category_id so we can later detect that the Job for that // category_id has completed in order to know to fire the ResourceUpdateWasCompleted Event $last_category_id = $categories->last()->id; foreach ($categories as $category) { $job = new UpdatePerformerPopularityJob($harvest, $category->id, $last_category_id); $this->dispatch($job); } }
/** * Handle the event. * * @param ResourceUpdateWasCompleted $event * * @return void */ public function handle(ResourceUpdateWasCompleted $event) { $status = Harvest::where('resource', '=', $event->harvest->resource)->where('action', '=', $event->harvest->action)->firstOrFail(); $status->last_run_at = $event->startTime; $status->save(); }