|
|
|
@ -19,12 +19,15 @@ class CmdTasksModel extends Model{
|
|
|
|
|
//获取待执行任务
|
|
|
|
|
public function getTask()
|
|
|
|
|
{
|
|
|
|
|
//按顺序获取任务
|
|
|
|
|
$has_run = $this->where(['status'=>"1"])->count();
|
|
|
|
|
if($has_run > 0){
|
|
|
|
|
$has_run = $this->where(['status'=>"1"])->find();
|
|
|
|
|
if($has_run){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$task = $this->field("id,params")->where(['status'=>"0"])->order("id asc")->find();
|
|
|
|
|
$where = [
|
|
|
|
|
'status'=>"0",
|
|
|
|
|
'schedule_time'=>['ELT',time()]
|
|
|
|
|
];
|
|
|
|
|
$task = $this->field("id,params")->where($where)->order("id asc")->find();
|
|
|
|
|
if(empty($task)){
|
|
|
|
|
return false;
|
|
|
|
|
}else{
|
|
|
|
@ -49,7 +52,7 @@ class CmdTasksModel extends Model{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//插入任务
|
|
|
|
|
public function addTask($type,$params,$repeat=false,$need_path=true)
|
|
|
|
|
public function addTask($type,$params,$repeat=false,$need_path=true,$checkScheduleTime = 0)
|
|
|
|
|
{
|
|
|
|
|
if(!$repeat){
|
|
|
|
|
if(!$this->isCanAddTask($type)) return false;
|
|
|
|
@ -68,14 +71,27 @@ class CmdTasksModel extends Model{
|
|
|
|
|
"uid"=>$_SESSION['onethink_admin']['user_auth']['uid'],
|
|
|
|
|
"created_time"=>time(),
|
|
|
|
|
"params"=>$params,
|
|
|
|
|
"type"=>$type
|
|
|
|
|
"type"=>$type,
|
|
|
|
|
"schedule_time"=>$checkScheduleTime
|
|
|
|
|
];
|
|
|
|
|
return $this->add($save);
|
|
|
|
|
}
|
|
|
|
|
public function addScheduleTask($type,$params,$checkScheduleTime = 0)
|
|
|
|
|
{
|
|
|
|
|
$this->addTask($type,$params,true,true,$checkScheduleTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//验证任务
|
|
|
|
|
public function isCanAddTask($type)
|
|
|
|
|
public function isCanAddTask($type,$checkScheduleTime=false)
|
|
|
|
|
{
|
|
|
|
|
$task = $this->field("end_time")->where(['status'=>["in","0,1"],'type'=>$type])->order("id desc")->find();
|
|
|
|
|
$where = [
|
|
|
|
|
'status'=>["in","0,1"],
|
|
|
|
|
'type'=>$type
|
|
|
|
|
];
|
|
|
|
|
if(!$checkScheduleTime){
|
|
|
|
|
$where['schedule_time'] = 0;
|
|
|
|
|
}
|
|
|
|
|
$task = $this->field("end_time")->where($where)->order("id desc")->find();
|
|
|
|
|
if(!empty($task)){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|