public function create($action, $uid, $taskdata, $pre_task = 0)
{
if (!isset(\Tasks::$types[$action])) {
return $this->err('任务类型错误');
}
if (in_array($action, array('checkout', 'update', 'delete'))) {
if (!isset($taskdata['project_id'])) {
return $this->err('需要project_id');
}
}
if (in_array($action, array('rsync'))) {
if (!isset($taskdata['server_id'])) {
return $this->err('需要server_id');
}
}
$record = new \Tasks();
$record->type = $action;
$record->command = json_encode($taskdata);
$record->pre_task = $pre_task;
$record->status = 'created';
$record->create_time = date('Y-m-d H:i:s');
$record->execute_time = '0000-00-00 00:00:00';
$record->output = '';
$record->uid = $uid;
$record->save();
return $record->id;
}