rabin 7 years ago
parent
commit
eca4d8ed52
3 changed files with 77 additions and 25 deletions
  1. 8 23
      database/project.php
  2. 7 2
      lib/Api.php
  3. 62 0
      lib/Cron.php

+ 8 - 23
database/project.php

@@ -12,9 +12,7 @@ $local = array
 $status = array
 (
 	1 => '待机',
-	2 => '运行中',
-	3 => '抓取中',
-	4 => '已完成',
+	2 => '入队',
 );
 
 $cate = function()
@@ -157,7 +155,8 @@ return array
 			'match' 	=> 'is_numeric',
 			'option' 	=> $status,
 			'list'		=> true,
-			//'update'	=> 'radio',
+			'update'	=> 'radio',
+			'edit'		=> true,
 		),
 
 		'num'		=> array
@@ -192,20 +191,6 @@ return array
 			'update'	=> 'text',
 		),
 
-		'reorder'		=> array
-		(
-			'type' 		=> 'int-11',
-			'name' 		=> '排序(数值越大越靠前)',
-			'default' 	=> '1',
-			'desc' 		=> '请输入排序',
-			'match' 	=> 'option',
-			//'update'	=> 'text',
-			'search'	=> 'order',
-			'list'		=> true,
-			'edit'		=> true,
-			'order'		=> 'desc',
-		),
-
 		'state'		=> array
 		(
 			'type' 		=> 'tinyint-1',
@@ -257,18 +242,18 @@ return array
 	# request 请求接口定义
 	'request' => array
 	(	
-		# 获取所有待机并且符合当前时间的配置
+		# 获取所有入队并且符合当前时间的配置
 		'get' => array
 		(
 			'option' => array
 			(
 				'id' => 'yes',
-				'status' => array('yes', '<='),
-				'sdate' => array('yes-sdate`+`time', '<='),
+				'status' => 2,
+				'sdate' => array('yes-sdate`+`interval', '<='),
 				'state' => 1,
 			),
 			'type' => 'all',
-			'order' => array('reorder' => 'desc', 'id' => 'desc'),
+			'order' => array('id' => 'desc'),
 			'col' => '*',
 		),
 
@@ -279,7 +264,7 @@ return array
 			(
 				'id' => 'yes',
 				'status' => array('yes'),
-				'sdate' => array('yes-sdate`+`time', '<='),
+				'sdate' => array('yes-sdate`+`interval', '<='),
 				'state' => 1,
 			),
 			'type' => 'one',

+ 7 - 2
lib/Api.php

@@ -34,6 +34,7 @@ class Api
 		if (!$this->queue) {
 			$this->queue = new Queue('db');
 		}
+		Dever::import('task');
 		$state = true;
 		while ($state) {
 			$state = $this->load();
@@ -45,8 +46,12 @@ class Api
 		$config = $this->queue->pop();
 		if ($config) {
 			# 此处开task
-			$col = $this->col($config['id']);
-			$this->parse($config['url'], $config['id'], $config['collect_rule'], $col);
+			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;

+ 62 - 0
lib/Cron.php

@@ -0,0 +1,62 @@
+<?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();
+	}
+}