1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace Spider\Lib;
- use Dever;
- class Cron
- {
- private $queue;
- public function project()
- {
- $param['option_sdate'] = time();
- return Dever::db('spider/project')->get($param);
- }
- public function test_api($id)
- {
- $project = $this->project();
- foreach ($project as $k => $v) {
-
- }
- }
- private function cron()
- {
- if (!$this->queue) {
- $this->queue = new Queue('db');
- }
- Dever::import('task');
- $state = true;
- while ($state) {
- $state = $this->load();
- }
- }
- private function load()
- {
- $config = $this->queue->pop();
- if ($config) {
- # 此处开task
- Dever::task(function() use($config, $this)
- {
- $col = $this->col($config['id']);
- $this->parse($config['url'], $config['id'], $config['collect_rule'], $col);
- });
-
- $state = true;
- } else {
- $state = false;
- }
- return $state;
- }
- private function col($project)
- {
- return Dever::db('spider/col')->getList(['where_project_id' => $project]);
- }
- private function parse($url, $project, $rule, $col)
- {
- $parse = new Parse($url, $project, $rule, $col);
- return $parse->get();
- }
- }
|