/** * Execute console command. */ public function handle() { if ($this->option('jobs') || $this->option('all')) { $this->jobsManager->deleteAll(); } if ($this->option('proxies') || $this->option('all')) { $this->proxy->reset(); } return true; }
/** * Reset download jobs. */ function downloadNewLaws() { $this->jobsManager->deleteAll('download'); $laws = DB::table('laws')->where('date', '<', max_date())->whereIn('status', [Law::NOT_DOWNLOADED, Law::DOWNLOADED_BUT_NEEDS_UPDATE])->select('id', 'status')->get(); foreach ($laws as $law) { $this->jobsManager->add('command.lawgrabber.download', 'downloadCard', ['id' => $law->id, 're_download' => $law->status == Law::DOWNLOADED_BUT_NEEDS_UPDATE], 'download', 1); } // Cards with ??.??.???? should be rescanned only once in a while. $laws = DB::table('laws')->where('date', '<', max_date())->where('status', Law::DOWNLOADED_BUT_HAS_UNKNOWN_REVISION)->where('card_updated', '<', time() + 3600 * 24)->select('id')->get(); foreach ($laws as $law) { $this->jobsManager->add('command.lawgrabber.download', 'downloadCard', ['id' => $law->id, 're_download' => true], 'download', 1); } $revisions = DB::table('law_revisions')->where('status', Revision::NEEDS_UPDATE)->select('law_id', 'date')->get(); foreach ($revisions as $revision) { $this->jobsManager->add('command.lawgrabber.download', 'downloadRevision', ['law_id' => $revision->law_id, 'date' => $revision->date], 'download'); } }
/** * Schedule crawls of each law list pages. * * @param null $starting_date If not passed or null, the 1991-01-01 will be taken as default. * @param bool $re_download Whether or not force re-download of the listings. Might be useful when updating recent days. */ protected function addLawListJobs($starting_date = null, $re_download = false) { $this->jobsManager->deleteAll('discover'); $date = strtotime($starting_date ?: '1991-01-01 00:00:00'); $date = max($date, strtotime('1991-01-01 00:00:00')); if ($date <= strtotime('1991-01-01 00:00:00')) { $this->jobsManager->add('command.lawgrabber.discover', 'discoverDailyLawList', ['law_list_url' => '/laws/main/ay1990/page', 'date' => date('Y-m-d', $date)], 'discover'); } while ($date <= strtotime('midnight') && (!max_date() || max_date() && $date < strtotime(max_date()))) { $this->jobsManager->add('command.lawgrabber.discover', 'discoverDailyLawList', ['law_list_url' => '/laws/main/a' . date('Ymd', $date) . '/sp5/page', 'date' => date('Y-m-d', $date), 're_download' => $re_download], 'discover', 5); $date = strtotime(date('c', $date) . '+1 day'); } }