This question is similar to this one except that:
- I need to send the output of the chained (2nd, 3rd or 4th) commands in an output (email in this case)
Original Scheduler Code
This is working fine - both command and the email output:
protected function schedule(Schedule $schedule)
{
$schedule ->command('commandA:myoption')
->emailOutputTo('myemail@gmail.com');
}
Chained / Series Commands
When I try and create a chain using a then function it doesn't seem to work:
Option 1 - try to include output into a common email
Result = commandB not performed, only emails the commandA output:
protected function schedule(Schedule $schedule) {
$schedule ->command('commandA:myoption')
->then(function(Schedule $schedule) {
return $schedule->command('commandB:myoption');
})
->emailOutputTo('myemail@gmail.com');
}
Option 2 - try to include output into a common email
(by sending separate email outputs in the primary and 2nd commands)
Result = commandB not performed, only emails the commandA output:
protected function schedule(Schedule $schedule) {
$schedule ->command('commandA:myoption')
->then(function(Schedule $schedule) {
$schedule->command('commandB:myoption')
->emailOutputTo('myemail@gmail.com');
})
->emailOutputTo('myemail@gmail.com');
}
also tried this variation, with no success (same result)
protected function schedule(Schedule $schedule) {
$schedule ->command('commandA:myoption')
->then(function() use($schedule) {
return $schedule->command('commandB:myoption')
->emailOutputTo('myemail@gmail.com');
})
->emailOutputTo('myemail@gmail.com');
}
Previous SO Answer
The aforementioned accepted answer runs commandB correctly but does not include the output for commandB in the email:
protected function schedule(Schedule $schedule) {
$schedule ->command('commandA:myoption')
->then(function() {
return $this->call('commandB:myoption');
})
->emailOutputTo('myemail@gmail.com');
}
...and as noted here it's not possible to email from a Scheduler ->call() method, only when using the ->command() method :
The emailOutputTo, sendOutputTo and appendOutputTo methods are exclusive to the command method and are not supported for call.
A modification of the aforementioned accepted answer gives the following error:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Type error: Too few arguments to function Illuminate\Foundation\Console\Kernel::command(), 1 passed in /app/Console/Kernel.php on line 33 and exactly 2 expected
protected function schedule(Schedule $schedule) {
$schedule ->command('commandA:myoption')
->then(function() {
$this->command('commandB:myoption');
->emailOutputTo('myemail@gmail.com');
})
->emailOutputTo('myemail@gmail.com');
}
Question How do you chain commands in the scheduler and send the output from all commands to either
- a common email ?
- separate emails (if common isn't possible) ?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2lZ5Zog
via IFTTT
Aucun commentaire:
Enregistrer un commentaire