public function processQueue() { $queue = Database::queue(); $sites = Database::sites(); $c = $queue->find(); $c->sort(array('rnd' => 1)); $c->limit(20); $cnt = 0; while ($item = $c->getNext()) { $cnt++; $site = $sites->findOne(array('code' => $item['site'])); if (null === $site) { continue; } $parser = $this->initParser($site); if ('job' === $item['type']) { $time = time(); if ($parser->processJob($item['id'], $item['url'])) { $queue->remove(array('_id' => $item['_id'])); // stamps must be unique while (time() == $time) { sleep(1); } } } } if ($cnt > 0) { $this->updateGlobalRSS(); } }
/** * Method to return sites array */ private function getSites($ver = 0) { if (self::VSITES === $ver) { return false; } $c = Database::sites(); $sites = array(); $cursor = $c->find(); while ($site = $cursor->getNext()) { $sites[] = array('i' => $site['code'], 'f' => $site['folder'], 'n' => $site['name'], 'u' => $site['url']); } return array('v' => self::VSITES, 'vl' => $sites); }
private function initParser($folder) { if (isset($this->parsers[$folder])) { return $this->parsers[$folder]; } $site = Database::sites()->findOne(array('folder' => $folder)); if (!is_array($site)) { // FIXME just for test return false; } $this->assertTrue(is_array($site)); $this->assertArrayHasKey('class', $site); $parser = new $site['class'](); $this->assertTrue($parser instanceof Parser); $this->assertTrue($parser instanceof IParser); $this->parsers[$folder] = $parser; return $parser; }
protected function prepare($query) { $this->preview = isset($_GET['preview']); $site = array_shift($query); $id = array_shift($query); if (!$site || !$id || isset(self::$sites[$site]) && !self::$sites[$site]) { return Module::NotFound(); } if (!isset(self::$sites[$site])) { self::$sites[$site] = Database::sites()->findOne(array('folder' => $site)); } $this->site = self::$sites[$site]; if (!$this->site) { return false; } $this->job = Database::jobs()->findOne(array('site' => (int) $this->site['code'], 'id' => (string) $id)); if (!$this->job) { return false; } return true; }
protected function getScript() { $sites = Database::sites()->find()->sort(array('code' => 1)); $content = <<<EOF var data = new google.visualization.DataTable(); data.addColumn('string', 'date'); EOF; while ($site = $sites->getNext()) { $content .= <<<EOF data.addColumn('number', '{$site['name']}'); EOF; } $content .= <<<EOF data.addRows(7); EOF; $sites->reset(); $now = getdate(); $dt = mktime(0, 0, 0, $now['mon'], $now['mday'], $now['year']); $i = 6; // week for stats while ($i > -1) { $dth = date('d.m', $dt); $content .= <<<EOF data.setValue({$i}, 0, '{$dth}'); EOF; $n = 1; while ($site = $sites->getNext()) { $c = Database::jobs()->find(array('site' => $site['code'], 'stamp' => array('$gte' => $dt, '$lt' => $dt + 60 * 60 * 24)))->count(); $content .= <<<EOF data.setValue({$i}, {$n}, {$c}); EOF; ++$n; } $sites->reset(); --$i; $dt -= 60 * 60 * 24; } $content .= <<<EOF new google.visualization.LineChart( \tdocument.getElementById('weekjobs') ).draw(data, { \theight: 350, \twidth: 800, \tbackgroundColor: { \t\tstroke: '#858585', \t\tstrokeWidth: 1, \t\tfill: '#2e3436' \t}, \tlegendTextStyle: { \t\tcolor: 'white' \t}, \tvAxis: { \t\tbaselineColor: '#858585', \t\ttextStyle: { \t\t\tcolor: 'white' \t\t} \t}, \thAxis: { \t\tbaselineColor: '#858585', \t\ttextStyle: { \t\t\tcolor: 'white' \t\t} \t}, \tcurveType: 'function', \tchartArea: { \t\tleft: 60, \t\ttop: 55, \t\twidth: 550 \t}, \tpointSize: 3, \tfontName: 'Tahoma', \tmin: 0, \tlegend: 'right' }); EOF; return array('google.load(\'visualization\', \'1\', {packages: [\'corechart\']});', $content); }