29.07.2016 Views

laravel-5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Task Scheduling 349<br />

.<br />

1 $schedule->command('emails:send')->daily()->when(function () {<br />

2 return true;<br />

3 });<br />

Preventing Task Overlaps<br />

By default, scheduled tasks will be run even if the previous instance of the task is still running. To<br />

prevent this, you may use the withoutOverlapping method:<br />

.<br />

1 $schedule->command('emails:send')->withoutOverlapping();<br />

In this example, the emails:send Artisan command will be run every minute if it is not already<br />

running. The withoutOverlapping method is especially useful if you have tasks that vary drastically<br />

in their execution time, preventing you from predicting exactly how long a given task will take.<br />

Task Output<br />

The Laravel scheduler provides several convenient methods for working with the output generated<br />

by scheduled tasks. First, using the sendOutputTo method, you may send the output to a file for later<br />

inspection:<br />

.<br />

1 $schedule->command('emails:send')<br />

2 ->daily()<br />

3 ->sendOutputTo($filePath);<br />

Using the emailOutputTo method, you may e-mail the output to an e-mail address of your choice.<br />

Note that the output must first be sent to a file using the sendOutputTo method. Also, before e-<br />

mailing the output of a task, you should configure Laravel’s e-mail services:<br />

.<br />

1 $schedule->command('foo')<br />

2 ->daily()<br />

3 ->sendOutputTo($filePath)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!