Skip to content

Commit

Permalink
统一Task命名空间为TaskModel
Browse files Browse the repository at this point in the history
  • Loading branch information
littlehz committed May 16, 2016
1 parent 82526e6 commit 930fc55
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
38 changes: 19 additions & 19 deletions components/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@

use Yii;
use app\models\Project;
use app\models\Task;
use app\models\Task as TaskModel;

class Folder extends Ansible {

/**
* 初始化宿主机部署工作空间
*
* @param Task $task
* @param TaskModel $task
* @return bool|int
*/
public function initLocalWorkspace(Task $task) {
public function initLocalWorkspace(TaskModel $task) {

$version = $task->link_id;
$branch = $task->branch;
Expand Down Expand Up @@ -62,11 +62,11 @@ public function initRemoteVersion($version) {
* 将多个文件/目录通过tar + scp传输到指定的多个目标机
*
* @param Project $project
* @param Task $task
* @param TaskModel $task
* @return bool
* @throws \Exception
*/
public function scpCopyFiles(Project $project, Task $task) {
public function scpCopyFiles(Project $project, TaskModel $task) {

// 1. 宿主机 tar 打包
$this->_packageFiles($project, $task);
Expand All @@ -87,11 +87,11 @@ public function scpCopyFiles(Project $project, Task $task) {
* 将多个文件/目录通过tar + ansible传输到指定的多个目标机
*
* @param Project $project
* @param Task $task
* @param TaskModel $task
* @return bool
* @throws \Exception
*/
public function ansibleCopyFiles(Project $project, Task $task) {
public function ansibleCopyFiles(Project $project, TaskModel $task) {

// 1. 宿主机 tar 打包
$this->_packageFiles($project, $task);
Expand All @@ -107,11 +107,11 @@ public function ansibleCopyFiles(Project $project, Task $task) {

/**
* @param Project $project
* @param Task $task
* @param TaskModel $task
* @return bool
* @throws \Exception
*/
protected function _packageFiles(Project $project, Task $task) {
protected function _packageFiles(Project $project, TaskModel $task) {

$version = $task->link_id;
$files = $task->getCommandFiles();
Expand All @@ -134,11 +134,11 @@ protected function _packageFiles(Project $project, Task $task) {
/**
* @param $remoteHost
* @param Project $project
* @param Task $task
* @param TaskModel $task
* @return bool
* @throws \Exception
*/
protected function _copyPackageToServer($remoteHost, Project $project, Task $task) {
protected function _copyPackageToServer($remoteHost, Project $project, TaskModel $task) {

$version = $task->link_id;
$packagePath = Project::getDeployPackagePath($version);
Expand All @@ -163,11 +163,11 @@ protected function _copyPackageToServer($remoteHost, Project $project, Task $tas

/**
* @param Project $project
* @param Task $task
* @param TaskModel $task
* @return bool
* @throws \Exception
*/
protected function _copyPackageToServerByAnsible(Project $project, Task $task) {
protected function _copyPackageToServerByAnsible(Project $project, TaskModel $task) {

$version = $task->link_id;
$packagePath = Project::getDeployPackagePath($version);
Expand All @@ -183,11 +183,11 @@ protected function _copyPackageToServerByAnsible(Project $project, Task $task) {

/**
* @param Project $project
* @param Task $task
* @param TaskModel $task
* @return bool
* @throws \Exception
*/
protected function _unpackageFiles(Project $project, Task $task) {
protected function _unpackageFiles(Project $project, TaskModel $task) {

$version = $task->link_id;
$releasePackage = Project::getReleaseVersionPackage($version);
Expand All @@ -197,7 +197,7 @@ protected function _unpackageFiles(Project $project, Task $task) {

$cmd = [];

if ($task->file_transmission_mode == Task::FILE_TRANSMISSION_MODE_PART) {
if ($task->file_transmission_mode == TaskModel::FILE_TRANSMISSION_MODE_PART) {
// 增量传输时, 在解压数据包之前, 需要把目标机当前版本复制一份到release目录
$cmd[] = sprintf('cp -arf %s/. %s', $webrootPath, $releasePath);
}
Expand All @@ -220,11 +220,11 @@ protected function _unpackageFiles(Project $project, Task $task) {

/**
* @param Project $project
* @param Task $task
* @param TaskModel $task
* @return bool
* @throws \Exception
*/
protected function _unpackageFilesByAnsible(Project $project, Task $task) {
protected function _unpackageFilesByAnsible(Project $project, TaskModel $task) {

$version = $task->link_id;
$releasePackage = Project::getReleaseVersionPackage($version);
Expand All @@ -234,7 +234,7 @@ protected function _unpackageFilesByAnsible(Project $project, Task $task) {

$cmd = [];

if ($task->file_transmission_mode == Task::FILE_TRANSMISSION_MODE_PART) {
if ($task->file_transmission_mode == TaskModel::FILE_TRANSMISSION_MODE_PART) {
// 增量传输时, 在解压数据包之前, 需要把目标机当前版本复制一份到release目录
$cmd[] = sprintf('cp -arf %s/. %s', $webrootPath, $releasePath);
}
Expand Down
28 changes: 14 additions & 14 deletions controllers/WalleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use app\components\Task as WalleTask;
use app\models\Project;
use app\models\Record;
use app\models\Task;
use app\models\Task as TaskModel;
use yii;

class WalleController extends Controller {
Expand Down Expand Up @@ -48,7 +48,7 @@ class WalleController extends Controller {
protected $walleFolder;

public $enableCsrfValidation = false;

/**
* 发起上线
*
Expand All @@ -59,15 +59,15 @@ public function actionStartDeploy() {
if (!$taskId) {
$this->renderJson([], -1, yii::t('walle', 'deployment id is empty'));
}
$this->task = Task::findOne($taskId);
$this->task = TaskModel::findOne($taskId);
if (!$this->task) {
throw new \Exception(yii::t('walle', 'deployment id not exists'));
}
if ($this->task->user_id != $this->uid) {
throw new \Exception(yii::t('w', 'you are not master of project'));
}
// 任务失败或者审核通过时可发起上线
if (!in_array($this->task->status, [Task::STATUS_PASS, Task::STATUS_FAILED])) {
if (!in_array($this->task->status, [TaskModel::STATUS_PASS, TaskModel::STATUS_FAILED])) {
throw new \Exception(yii::t('walle', 'deployment only done for once'));
}
// 清除历史记录
Expand All @@ -78,7 +78,7 @@ public function actionStartDeploy() {
$this->walleTask = new WalleTask($this->conf);
$this->walleFolder = new Folder($this->conf);
try {
if ($this->task->action == Task::ACTION_ONLINE) {
if ($this->task->action == TaskModel::ACTION_ONLINE) {
$this->_makeVersion();
$this->_initWorkspace();
$this->_preDeploy();
Expand All @@ -96,14 +96,14 @@ public function actionStartDeploy() {

// 记录此次上线的版本(软链号)和上线之前的版本
///对于回滚的任务不记录线上版本
if ($this->task->action == Task::ACTION_ONLINE) {
if ($this->task->action == TaskModel::ACTION_ONLINE) {
$this->task->ex_link_id = $this->conf->version;
}
// 第一次上线的任务不能回滚、回滚的任务不能再回滚
if ($this->task->action == Task::ACTION_ROLLBACK || $this->task->id == 1) {
$this->task->enable_rollback = Task::ROLLBACK_FALSE;
if ($this->task->action == TaskModel::ACTION_ROLLBACK || $this->task->id == 1) {
$this->task->enable_rollback = TaskModel::ROLLBACK_FALSE;
}
$this->task->status = Task::STATUS_DONE;
$this->task->status = TaskModel::STATUS_DONE;
$this->task->save();

// 可回滚的版本设置
Expand All @@ -113,7 +113,7 @@ public function actionStartDeploy() {
$this->conf->version = $this->task->link_id;
$this->conf->save();
} catch (\Exception $e) {
$this->task->status = Task::STATUS_FAILED;
$this->task->status = TaskModel::STATUS_FAILED;
$this->task->save();
// 清理本地部署空间
$this->_cleanUpLocal($this->task->link_id);
Expand Down Expand Up @@ -330,7 +330,7 @@ public function actionGetCommitFile($projectId, $start, $end, $branch = 'trunk')
* @throws \Exception
*/
public function actionDeploy($taskId) {
$this->task = Task::find()
$this->task = TaskModel::find()
->where(['id' => $taskId])
->with(['project'])
->one();
Expand Down Expand Up @@ -516,8 +516,8 @@ private function _updateRemoteServers($version, $delay = 0) {
*/
private function _enableRollBack() {
$where = ' status = :status AND project_id = :project_id ';
$param = [':status' => Task::STATUS_DONE, ':project_id' => $this->task->project_id];
$offset = Task::find()
$param = [':status' => TaskModel::STATUS_DONE, ':project_id' => $this->task->project_id];
$offset = TaskModel::find()
->select(['id'])
->where($where, $param)
->orderBy(['id' => SORT_DESC])
Expand All @@ -527,7 +527,7 @@ private function _enableRollBack() {

$where .= ' AND id <= :offset ';
$param[':offset'] = $offset;
return Task::updateAll(['enable_rollback' => Task::ROLLBACK_FALSE], $where, $param);
return TaskModel::updateAll(['enable_rollback' => TaskModel::ROLLBACK_FALSE], $where, $param);
}

/**
Expand Down

0 comments on commit 930fc55

Please sign in to comment.