samedi 28 octobre 2017

Laravel job dumps exec() error into command line instead of $output

I am trying to build a simple deployer in Laravel, that will receive a webhook, perform a deployment and store some information (from the hook) about said deployment.

I am using Laravel 5.2 jobs dispatcher to perform the following:

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)
    );
}

My understanding of the exec() function is that this should not dump any errors directly, but will store them in $output.

However, when I run php artisan queue:work on my server in the command line, to test the job dispatcher, I just immediately get fatal: Not a git repository (or any of the parent directories): .git dumped into the command line output. This git error is correct, but it is making the job "fail" as though exec() threw an error. Is this correct? My job should be reporting the error in its own way, as follows:

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();
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire