2
我试图在Laravel中构建一个简单的部署器,它将接收webhook,执行部署并存储关于部署的一些信息(从挂钩)。
我使用Laravel 5.2作业调度程序来执行以下操作:
public function deploy()
{
$result = 0;
$output = array();
exec('cd ' . $this->deploymentMapping->full_file_path . '; git pull', $output, $result);
return array(
'result' => $result,
'output' => $this->outputToString($output)
);
}
我的exec()
功能的理解是,这不应该直接倾倒任何错误,但是将它们存储在$output
。
但是,当我在命令行中运行我服务器上的php artisan queue:work
时,为了测试作业调度程序,我立即将fatal: Not a git repository (or any of the parent directories): .git
转储到命令行输出中。 这个混帐错误是正确的,但它使作业“失败”,就好像exec()
抛出一个错误。它是否正确?我的工作应该是报告以自己的方式错误,如下所示:
public function handle()
{
$deploymentAttempt = new DeploymentAttempt();
$deploymentAttempt->deployment_id = $this->deploymentID;
$gitResponse = $this->deployer->deploy(); //the above function
$deploymentAttempt->success = !($gitResponse['result'] > 0);
$deploymentAttempt->message = $gitResponse['output'];
$deploymentAttempt->save();
}
谢谢!导致作业失败的错误实际上不是StdOut/StdErr的这个问题,它实际上是我编写'$ deploymentAttempt-> success'而不是'$ deploymentAttempt-> successful'。我是丁丁。谢谢你的帮助 :) – k4kuz0