Event
class Event
Traits
Constants
| protected EXIT_CODE_CONTEXT_KEY_PREFIX |
Context key prefix for the current run's exit code. |
| protected PROCESS_CONTEXT_KEY_PREFIX |
Context key prefix for the current run's process. |
| protected SKIPPED_BECAUSE_OVERLAPPING_CONTEXT_KEY_PREFIX |
Context key prefix for the current run's overlap skip state. |
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| string | $expression | The cron expression representing the event's frequency. |
from ManagesAttributes |
| int|null | $repeatSeconds | How often to repeat the event during a minute. |
from ManagesAttributes |
| DateTimeZone|string|null | $timezone | The timezone the date should be evaluated on. |
from ManagesAttributes |
| array | $environments | The list of environments the command should run under. |
from ManagesAttributes |
| bool | $evenInMaintenanceMode | Indicates if the command should run in maintenance mode. |
from ManagesAttributes |
| bool | $evenWhenPaused | Indicates if the command should run even when the scheduler is paused. |
from ManagesAttributes |
| bool | $withoutOverlapping | Indicates if the command should not overlap itself. |
from ManagesAttributes |
| bool | $releaseOnTerminationSignals | Indicates if the mutex should be released when the process receives a termination signal. |
from ManagesAttributes |
| bool | $onOneServer | Indicates if the command should only be allowed to run on one server for each cron expression. |
from ManagesAttributes |
| int | $expiresAt | The number of minutes the mutex should be valid. |
from ManagesAttributes |
| bool | $runInBackground | Indicates if the command should run in the background. |
from ManagesAttributes |
| protected array | $filters | The array of filter callbacks. |
from ManagesAttributes |
| protected array | $rejects | The array of reject callbacks. |
from ManagesAttributes |
| string|null | $description | The human-readable description of the event. |
from ManagesAttributes |
| array | $attributes | The arbitrary attributes stored with the event. |
from ManagesAttributes |
| string|null | $command | The command string. |
|
| string|null | $output | The location that output should be sent to. |
|
| bool | $shouldAppendOutput | Indicates whether output should be appended. |
|
| protected array | $beforeCallbacks | The array of callbacks to be run before the event is started. |
|
| protected array | $afterCallbacks | The array of callbacks to be run after the event is finished. |
|
| Closure|null | $mutexNameResolver | The mutex name resolver callback. |
|
| CarbonInterface|null | $lastChecked | The last time the event was checked for eligibility to run. |
|
| int|null | $exitCode | The exit status code of the command. |
|
| bool | $isSystem | Determines if the event is system command. |
|
| protected bool | $ensureOutputIsBeingCaptured | Determines if output should be captured. |
|
| bool | $skippedBecauseOverlapping | Indicates whether the execution was skipped due to the mutex already being reserved. |
|
| protected bool | $mutexAcquired | Indicates whether this event currently owns the overlapping mutex. |
Methods
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Limit the environments the command should run in.
State that the command should run even in maintenance mode.
State that the command should run even when the scheduler is paused.
Do not allow the event to overlap each other.
Allow the event to only run on one server for each cron expression.
State that the command should run in the background.
Register a callback to further filter the schedule.
Register a callback to further filter the schedule.
Set the human-friendly description of the event.
Set the human-friendly description of the event.
Set arbitrary attributes to store with the event.
The Cron expression representing the event's frequency.
Schedule the event to run between start and end time.
Schedule the event to not run between start and end time.
Schedule the event to run every two seconds.
Schedule the event to run every five seconds.
Schedule the event to run every ten seconds.
Schedule the event to run every fifteen seconds.
Schedule the event to run every twenty seconds.
Schedule the event to run every thirty seconds.
Schedule the event to run multiple times per minute.
Schedule the event to run every two minutes.
Schedule the event to run every three minutes.
Schedule the event to run every four minutes.
Schedule the event to run every five minutes.
Schedule the event to run every ten minutes.
Schedule the event to run every fifteen minutes.
Schedule the event to run every thirty minutes.
Schedule the event to run hourly at a given offset in the hour.
Schedule the event to run every odd hour.
Schedule the event to run every two hours.
Schedule the event to run every three hours.
Schedule the event to run every four hours.
Schedule the event to run every six hours.
Schedule the event to run daily at a given time (10:00, 19:30, etc).
Schedule the event to run twice daily.
Schedule the event to run twice daily at a given offset.
Schedule the event to run at the given minutes and hours.
Schedule the event to run only on Wednesdays.
Schedule the event to run weekly on a given day and time.
Schedule the event to run monthly on a given day and time.
Schedule the event to run twice monthly at a given time.
Schedule the event to run on the last day of the month.
Schedule the event to run on specific days of the month.
Schedule the event to run quarterly on a given day and time.
Schedule the event to run yearly on a given month, day, and time.
Set the days of the week the command should run on.
Splice the given value into the given position of the expression.
Get the class name of the first parameter of the given Closure.
Get the class names of the first parameter of the given Closure, including union types.
Get the class names / types of the parameters of the given Closure.
Get the class names / types of the return type of the given Closure.
Call the given Closure with this instance then return the instance.
Create a new event instance.
Determine if the event should skip because another process is overlapping.
Determine if the event has been configured to repeat multiple times per minute.
Determine if the event is ready to repeat.
Get the output of the system command process.
Determine if the given event should run based on the Cron expression at the given time.
Determine if the event runs in maintenance mode.
Determine if the event runs when the scheduler is paused.
Determine if the event runs in the given environment.
Ensure that the output is stored on disk in a log file.
Send the output of the command to a given location.
Append the output of the command to a given location.
E-mail the results of the scheduled operation.
E-mail the results of the scheduled operation if it produces output.
E-mail the results of the scheduled operation if it fails.
Ensure that the command output is being captured.
E-mail the output of the event to the recipients.
Get the e-mail subject line for output results.
Register a callback to ping a given URL before the job runs.
Register a callback to ping a given URL before the job runs if the given condition is true.
Register a callback to ping a given URL after the job runs if the given condition is true.
Register a callback to ping a given URL if the operation succeeds.
Register a callback to ping a given URL if the operation succeeds and if the given condition is true.
Register a callback to ping a given URL if the operation fails.
Register a callback to ping a given URL if the operation fails and if the given condition is true.
Get the callback that pings the given URL.
Register a callback that uses the output after the job runs.
Register a callback that uses the output if the operation succeeds.
Register a callback that uses the output if the operation fails.
Get a callback that provides output.
Call the given event callback.
Get the summary of the event for display.
Determine the next due date for an event.
Get the Cron expression for the event.
Get the mutex name for the scheduled command.
Release the event mutex if this process owns it during signal termination.
Delete the mutex for the event.
Set the exit code for the current event run.
Get the exit code for the current event run.
Determine if this event's most recent run in the current coroutine was skipped due to overlapping.
Get the context key for this event's current run.
Get the context key for this event's current process.
Get the context key for this event's overlap skip state.
Format the given command string with a normalized PHP binary path.
Flush all static state.
Details
in
Macroable at line 30
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 44
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 72
static void
flushMacros()
Flush the existing macros.
Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 108
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
in
ManagesAttributes at line 97
ManagesAttributes
environments(UnitEnum|array|string $environments)
Limit the environments the command should run in.
in
ManagesAttributes at line 112
ManagesAttributes
evenInMaintenanceMode()
State that the command should run even in maintenance mode.
in
ManagesAttributes at line 124
ManagesAttributes
evenWhenPaused()
State that the command should run even when the scheduler is paused.
in
ManagesAttributes at line 138
ManagesAttributes
withoutOverlapping(int $expiresAt = 1440, bool $releaseOnTerminationSignals = true)
Do not allow the event to overlap each other.
The expiration time of the underlying cache lock may be specified in minutes.
in
ManagesAttributes at line 156
ManagesAttributes
onOneServer()
Allow the event to only run on one server for each cron expression.
in
ManagesAttributes at line 168
ManagesAttributes
runInBackground()
State that the command should run in the background.
in
ManagesAttributes at line 180
ManagesAttributes
when(bool|callable $callback)
Register a callback to further filter the schedule.
in
ManagesAttributes at line 194
ManagesAttributes
skip(bool|callable $callback)
Register a callback to further filter the schedule.
in
ManagesAttributes at line 208
ManagesAttributes
name(string $description)
Set the human-friendly description of the event.
in
ManagesAttributes at line 218
ManagesAttributes
description(string $description)
Set the human-friendly description of the event.
in
ManagesAttributes at line 230
ManagesAttributes
withAttributes(array $attributes)
Set arbitrary attributes to store with the event.
in
ManagesFrequencies at line 22
ManagesFrequencies
cron(string $expression)
The Cron expression representing the event's frequency.
in
ManagesFrequencies at line 34
ManagesFrequencies
between(string $startTime, string $endTime)
Schedule the event to run between start and end time.
in
ManagesFrequencies at line 44
ManagesFrequencies
unlessBetween(string $startTime, string $endTime)
Schedule the event to not run between start and end time.
in
ManagesFrequencies at line 78
ManagesFrequencies
everySecond()
Schedule the event to run every second.
in
ManagesFrequencies at line 88
ManagesFrequencies
everyTwoSeconds()
Schedule the event to run every two seconds.
in
ManagesFrequencies at line 98
ManagesFrequencies
everyFiveSeconds()
Schedule the event to run every five seconds.
in
ManagesFrequencies at line 108
ManagesFrequencies
everyTenSeconds()
Schedule the event to run every ten seconds.
in
ManagesFrequencies at line 118
ManagesFrequencies
everyFifteenSeconds()
Schedule the event to run every fifteen seconds.
in
ManagesFrequencies at line 128
ManagesFrequencies
everyTwentySeconds()
Schedule the event to run every twenty seconds.
in
ManagesFrequencies at line 138
ManagesFrequencies
everyThirtySeconds()
Schedule the event to run every thirty seconds.
in
ManagesFrequencies at line 151
protected ManagesFrequencies
repeatEvery(int $seconds)
Schedule the event to run multiple times per minute.
in
ManagesFrequencies at line 171
ManagesFrequencies
everyMinute()
Schedule the event to run every minute.
in
ManagesFrequencies at line 181
ManagesFrequencies
everyTwoMinutes()
Schedule the event to run every two minutes.
in
ManagesFrequencies at line 191
ManagesFrequencies
everyThreeMinutes()
Schedule the event to run every three minutes.
in
ManagesFrequencies at line 201
ManagesFrequencies
everyFourMinutes()
Schedule the event to run every four minutes.
in
ManagesFrequencies at line 211
ManagesFrequencies
everyFiveMinutes()
Schedule the event to run every five minutes.
in
ManagesFrequencies at line 221
ManagesFrequencies
everyTenMinutes()
Schedule the event to run every ten minutes.
in
ManagesFrequencies at line 231
ManagesFrequencies
everyFifteenMinutes()
Schedule the event to run every fifteen minutes.
in
ManagesFrequencies at line 241
ManagesFrequencies
everyThirtyMinutes()
Schedule the event to run every thirty minutes.
in
ManagesFrequencies at line 251
ManagesFrequencies
hourly()
Schedule the event to run hourly.
in
ManagesFrequencies at line 262
ManagesFrequencies
hourlyAt(array|int|string $offset)
Schedule the event to run hourly at a given offset in the hour.
in
ManagesFrequencies at line 272
ManagesFrequencies
everyOddHour(array|int|string $offset = 0)
Schedule the event to run every odd hour.
in
ManagesFrequencies at line 282
ManagesFrequencies
everyTwoHours(array|int|string $offset = 0)
Schedule the event to run every two hours.
in
ManagesFrequencies at line 292
ManagesFrequencies
everyThreeHours(array|int|string $offset = 0)
Schedule the event to run every three hours.
in
ManagesFrequencies at line 302
ManagesFrequencies
everyFourHours(array|int|string $offset = 0)
Schedule the event to run every four hours.
in
ManagesFrequencies at line 312
ManagesFrequencies
everySixHours(array|int|string $offset = 0)
Schedule the event to run every six hours.
in
ManagesFrequencies at line 322
ManagesFrequencies
daily()
Schedule the event to run daily.
in
ManagesFrequencies at line 332
ManagesFrequencies
at(string $time)
Schedule the command at a given time.
in
ManagesFrequencies at line 342
ManagesFrequencies
dailyAt(string $time)
Schedule the event to run daily at a given time (10:00, 19:30, etc).
in
ManagesFrequencies at line 359
ManagesFrequencies
twiceDaily(int $first = 1, int $second = 13)
Schedule the event to run twice daily.
in
ManagesFrequencies at line 372
ManagesFrequencies
twiceDailyAt(int $first = 1, int $second = 13, int $offset = 0)
Schedule the event to run twice daily at a given offset.
in
ManagesFrequencies at line 386
protected ManagesFrequencies
hourBasedSchedule(array|int|string $minutes, array|int|string $hours)
Schedule the event to run at the given minutes and hours.
in
ManagesFrequencies at line 401
ManagesFrequencies
weekdays()
Schedule the event to run only on weekdays.
in
ManagesFrequencies at line 411
ManagesFrequencies
weekends()
Schedule the event to run only on weekends.
in
ManagesFrequencies at line 421
ManagesFrequencies
mondays()
Schedule the event to run only on Mondays.
in
ManagesFrequencies at line 431
ManagesFrequencies
tuesdays()
Schedule the event to run only on Tuesdays.
in
ManagesFrequencies at line 441
ManagesFrequencies
wednesdays()
Schedule the event to run only on Wednesdays.
in
ManagesFrequencies at line 451
ManagesFrequencies
thursdays()
Schedule the event to run only on Thursdays.
in
ManagesFrequencies at line 461
ManagesFrequencies
fridays()
Schedule the event to run only on Fridays.
in
ManagesFrequencies at line 471
ManagesFrequencies
saturdays()
Schedule the event to run only on Saturdays.
in
ManagesFrequencies at line 481
ManagesFrequencies
sundays()
Schedule the event to run only on Sundays.
in
ManagesFrequencies at line 491
ManagesFrequencies
weekly()
Schedule the event to run weekly.
in
ManagesFrequencies at line 503
ManagesFrequencies
weeklyOn(mixed $dayOfWeek, string $time = '0:0')
Schedule the event to run weekly on a given day and time.
in
ManagesFrequencies at line 515
ManagesFrequencies
monthly()
Schedule the event to run monthly.
in
ManagesFrequencies at line 528
ManagesFrequencies
monthlyOn(int $dayOfMonth = 1, string $time = '0:0')
Schedule the event to run monthly on a given day and time.
in
ManagesFrequencies at line 542
ManagesFrequencies
twiceMonthly(int $first = 1, int $second = 16, string $time = '0:0')
Schedule the event to run twice monthly at a given time.
in
ManagesFrequencies at line 556
ManagesFrequencies
lastDayOfMonth(string $time = '0:0')
Schedule the event to run on the last day of the month.
in
ManagesFrequencies at line 569
ManagesFrequencies
daysOfMonth(int|array ...$days)
Schedule the event to run on specific days of the month.
in
ManagesFrequencies at line 584
ManagesFrequencies
quarterly()
Schedule the event to run quarterly.
in
ManagesFrequencies at line 597
ManagesFrequencies
quarterlyOn(int $dayOfQuarter = 1, string $time = '0:0')
Schedule the event to run quarterly on a given day and time.
in
ManagesFrequencies at line 610
ManagesFrequencies
yearly()
Schedule the event to run yearly.
in
ManagesFrequencies at line 623
ManagesFrequencies
yearlyOn(int $month = 1, int|string $dayOfMonth = 1, string $time = '0:0')
Schedule the event to run yearly on a given month, day, and time.
in
ManagesFrequencies at line 636
ManagesFrequencies
days(mixed $days)
Set the days of the week the command should run on.
in
ManagesFrequencies at line 648
ManagesFrequencies
timezone(DateTimeZone|UnitEnum|string $timezone)
Set the timezone the date should be evaluated on.
in
ManagesFrequencies at line 662
protected ManagesFrequencies
spliceIntoPosition(int $position, int|string $value)
Splice the given value into the given position of the expression.
in
ReflectsClosures at line 26
protected string
firstClosureParameterType(Closure $closure)
Get the class name of the first parameter of the given Closure.
in
ReflectsClosures at line 49
protected array
firstClosureParameterTypes(Closure $closure)
Get the class names of the first parameter of the given Closure, including union types.
in
ReflectsClosures at line 75
protected array
closureParameterTypes(Closure $closure)
Get the class names / types of the parameters of the given Closure.
in
ReflectsClosures at line 97
protected array
closureReturnTypes(Closure $closure)
Get the class names / types of the return type of the given Closure.
in
Tappable at line 17
mixed
tap(callable|null $callback = null)
Call the given Closure with this instance then return the instance.
at line 134
__construct(EventMutex $mutex, string|null $command = null, DateTimeZone|string|null $timezone = null, bool $isSystem = false)
Create a new event instance.
at line 150
mixed
run(Container $container)
Run the given event.
at line 211
bool
shouldSkipDueToOverlapping()
Determine if the event should skip because another process is overlapping.
at line 229
bool
isRepeatable()
Determine if the event has been configured to repeat multiple times per minute.
at line 237
bool
shouldRepeatNow()
Determine if the event is ready to repeat.
at line 249
protected int
start(Container $container)
Run the command process.
at line 259
protected int
execute(Container $container)
Run the command process.
at line 272
protected int
runProcess(Container $container)
Run the system command process.
at line 291
protected string|null
getProcessOutput()
Get the output of the system command process.
at line 303
void
finish(Container $container, int $exitCode)
Mark the command process as finished and run callbacks/cleanup.
at line 335
void
callBeforeCallbacks(Container $container)
Call all of the "before" callbacks for the event.
at line 345
void
callAfterCallbacks(Container $container)
Call all of the "after" callbacks for the event.
at line 357
bool
isDue(Application $app)
Determine if the given event should run based on the Cron expression.
at line 365
bool
isDueAt(Application $app, DateTimeInterface $time)
Determine if the given event should run based on the Cron expression at the given time.
at line 378
bool
runsInMaintenanceMode()
Determine if the event runs in maintenance mode.
at line 386
bool
runsWhenPaused()
Determine if the event runs when the scheduler is paused.
at line 394
protected bool
expressionPasses(DateTimeInterface $time)
Determine if the Cron expression passes.
at line 409
bool
runsInEnvironment(string $environment)
Determine if the event runs in the given environment.
at line 418
bool
filtersPass(Application $app)
Determine if the filters pass for the event.
at line 443
Event
storeOutput()
Ensure that the output is stored on disk in a log file.
at line 455
Event
sendOutputTo(string $location, bool $append = false)
Send the output of the command to a given location.
at line 467
void
writeOutput(Container $container)
Write the output of the command to the destination file.
at line 490
string|null
getOutput(Container $container)
Get the output for the event.
at line 504
Event
appendOutputTo(string $location)
Append the output of the command to a given location.
at line 516
Event
emailOutputTo(mixed $addresses, bool $onlyIfOutputExists = true)
E-mail the results of the scheduled operation.
at line 534
Event
emailWrittenOutputTo(mixed $addresses)
E-mail the results of the scheduled operation if it produces output.
at line 544
Event
emailOutputOnFailure(mixed $addresses)
E-mail the results of the scheduled operation if it fails.
at line 558
protected void
ensureOutputIsBeingCaptured()
Ensure that the command output is being captured.
at line 569
protected void
emailOutput(Mailer $mailer, Filesystem $filesystem, mixed $addresses, bool $onlyIfOutputExists = true)
E-mail the output of the event to the recipients.
at line 589
protected string
getEmailSubject()
Get the e-mail subject line for output results.
at line 603
Event
pingBefore(string $url)
Register a callback to ping a given URL before the job runs.
at line 613
Event
pingBeforeIf(bool $value, string $url)
Register a callback to ping a given URL before the job runs if the given condition is true.
at line 623
Event
thenPing(string $url)
Register a callback to ping a given URL after the job runs.
at line 633
Event
thenPingIf(bool $value, string $url)
Register a callback to ping a given URL after the job runs if the given condition is true.
at line 643
Event
pingOnSuccess(string $url)
Register a callback to ping a given URL if the operation succeeds.
at line 653
Event
pingOnSuccessIf(bool $value, string $url)
Register a callback to ping a given URL if the operation succeeds and if the given condition is true.
at line 663
Event
pingOnFailure(string $url)
Register a callback to ping a given URL if the operation fails.
at line 673
Event
pingOnFailureIf(bool $value, string $url)
Register a callback to ping a given URL if the operation fails and if the given condition is true.
at line 681
protected Closure
pingCallback(string $url)
Get the callback that pings the given URL.
at line 695
protected ClientInterface
getHttpClient(Container $container)
Get the Guzzle HTTP client to use to send pings.
at line 753
Event
thenWithOutput(Closure $callback, bool $onlyIfOutputExists = false)
Register a callback that uses the output after the job runs.
at line 765
Event
onSuccess(Closure $callback)
Register a callback to be called if the operation succeeds.
at line 785
Event
onSuccessWithOutput(Closure $callback, bool $onlyIfOutputExists = false)
Register a callback that uses the output if the operation succeeds.
at line 797
Event
onFailure(Closure $callback)
Register a callback to be called if the operation fails.
at line 817
Event
onFailureWithOutput(Closure $callback, bool $onlyIfOutputExists = false)
Register a callback that uses the output if the operation fails.
at line 827
protected Closure
withOutputCallback(Closure $callback, bool $onlyIfOutputExists = false)
Get a callback that provides output.
at line 841
protected string
readOutput(Filesystem $filesystem)
Read the captured event output.
at line 855
protected mixed
callEventCallback(Container $container, callable $callback, array $parameters = [])
Call the given event callback.
at line 872
protected array
eventParametersForCallback(Closure $callback)
Get the event parameters for the given callback.
at line 888
string
getSummaryForDisplay()
Get the summary of the event for display.
at line 900
CarbonInterface
nextRunDate(DateTimeInterface|string $currentTime = 'now', int $nth = 0, bool $allowCurrentDate = false)
Determine the next due date for an event.
at line 909
string
getExpression()
Get the Cron expression for the event.
at line 919
Event
preventOverlapsUsing(EventMutex $mutex)
Set the event mutex implementation to be used.
at line 929
string
mutexName()
Get the mutex name for the scheduled command.
at line 946
Event
createMutexNameUsing(Closure|string $mutexName)
Set the mutex name or name resolver callback.
at line 958
void
releaseMutexOnTerminationSignal()
Release the event mutex if this process owns it during signal termination.
at line 968
protected void
removeMutex()
Delete the mutex for the event.
at line 982
protected void
setExitCode(int $exitCode)
Set the exit code for the current event run.
at line 994
int|null
exitCode()
Get the exit code for the current event run.
at line 1002
bool
wasSkippedDueToOverlapping()
Determine if this event's most recent run in the current coroutine was skipped due to overlapping.
at line 1013
protected string
exitCodeContextKey()
Get the context key for this event's current run.
at line 1021
protected string
processContextKey()
Get the context key for this event's current process.
at line 1029
protected string
skippedBecauseOverlappingContextKey()
Get the context key for this event's overlap skip state.
at line 1037
static string
normalizeCommand(string $command)
Format the given command string with a normalized PHP binary path.
at line 1051
static void
flushState()
Flush all static state.