Esempio n. 1
0
 /**
  * Execute console command.
  */
 public function handle()
 {
     if ($this->option('single')) {
         $output = [];
         exec('pgrep -l -f "^php (.*?)artisan start"', $output);
         foreach ($output as $line) {
             $pid = preg_replace('|([0-9]+)(\\s.*)|u', '$1', $line);
             if ($pid != getmypid()) {
                 exec("kill -9 {$pid}");
             }
         }
     }
     if ($this->option('proxies')) {
         $this->workers = $this->option('proxies');
         $this->proxyManager->useProxy(true);
     }
     if ($this->proxyManager->useProxy()) {
         $this->proxyManager->connect($this->workers, $this->option('kill_old_proxies'));
     }
     if ($job_id = $this->option('job')) {
         $job = Job::find($job_id);
         if ($job) {
             $job->execute();
         } else {
             _log("Job {$job_id} is not found.");
         }
         return;
     }
     if (!$this->jobsManager->count()) {
         _log('No jobs found. Initializing a new discovery and download jobs.');
         $this->discoverer->discoverNewLaws();
         $this->downloader->downloadNewLaws();
     }
     $this->jobsManager->launch($this->workers);
 }
Esempio n. 2
0
 /**
  * See how many jobs there are.
  */
 public function count($group = null, $service = null, $method = null)
 {
     $query = Job::where('claimed', 0)->where('finished', 0);
     if ($group) {
         $query->where('group', $group);
     }
     if ($service) {
         $query->where('service', $service);
     }
     if ($method) {
         $query->where('method', $method);
     }
     return $query->count();
 }