Job
in package
uses
IntervalTrait
Class Job
Table of Contents
Properties
- $chainedJobs : array<string|int, mixed>
- $dependencies : array<string|int, mixed>
- $executionDuration : float
- $executionStartTime : float
- $maxAttempts : int
- $metadata : array<string|int, mixed>
- $onFailure : callable|null
- $onRetry : callable|null
- $onSuccess : callable|null
- $priority : string
- $queueId : string|null
- $retryCount : int
- $retryDelay : int
- $retryStrategy : string
- $tags : array<string|int, mixed>
- $timeout : int
- $after : callable|null
- $args : array<string|int, mixed>
- $at : string
- $backlink : string|null
- $before : callable|null
- $command : callable|string
- $creationTime : DateTime
- $emailConfig : array<string|int, mixed>
- $emailTo : array<string|int, mixed>
- $enabled : bool
- $executionTime : CronExpression
- $id : string
- $lockFile : string
- $output : string
- $outputMode : string
- $outputTo : array<string|int, mixed>
- $process : Process|null
- $returnCode : int
- $runInBackground : bool
- $successful : bool
- $tempDir : string
- $truthTest : bool
- $whenOverlapping : callable
Methods
- __construct() : mixed
- Create a new Job instance.
- april() : self
- Set the execution time to every April.
- at() : self
- Set the Job execution time.
- august() : self
- Set the execution time to every August.
- backlink() : string|null
- Sets/Gets an option backlink
- before() : self
- Set function to be called before job execution Job object is injected as a parameter to callable function.
- chain() : self
- Chain another job to run after this one
- configure() : self
- Configure the job.
- daily() : self
- Set the execution time to once a day.
- december() : self
- Set the execution time to every December.
- dependsOn() : self
- Add job dependency
- email() : self
- Set the emails where the output should be sent to.
- everyMinute() : self
- Set the execution time to every minute.
- february() : self
- Set the execution time to every February.
- finalize() : void
- Finish up processing the job
- friday() : self
- Set the execution time to every Friday.
- fromArray() : self
- Create job from array
- getArguments() : string|null
- Get optional arguments
- getAt() : string
- Get the cron 'at' syntax for this job
- getCommand() : Closure|string
- Get the command
- getCronExpression() : CronExpression
- getEnabled() : bool
- Get the status of this job
- getExecutionTime() : float
- Get execution time in seconds
- getId() : string
- Get the Job id.
- getMaxAttempts() : int
- Get maximum retry attempts
- getMetadata() : mixed
- Get job metadata
- getOutput() : mixed
- Get the job output.
- getPriority() : string
- Get job priority
- getProcess() : Process|null
- Get process (for background jobs)
- getQueueId() : string|null
- Get queue ID
- getRawArguments() : array<string|int, mixed>|string
- Get raw arguments (array or string)
- getRetryCount() : int
- Get current retry count
- getTags() : array<string|int, mixed>
- Get job tags
- hasTag() : bool
- Check if job has a specific tag
- hourly() : self
- Set the execution time to every hour.
- inForeground() : $this
- Force the Job to run in foreground.
- isDue() : bool
- Check if the Job is due to run.
- isOverlapping() : bool
- Check if the Job is overlapping.
- isSuccessful() : bool
- Get the status of the last run for this job
- january() : self
- Set the execution time to every January.
- july() : self
- Set the execution time to every July.
- june() : self
- Set the execution time to every June.
- march() : self
- Set the execution time to every March.
- maxAttempts() : self
- Set maximum retry attempts
- may() : self
- Set the execution time to every May.
- monday() : self
- Set the execution time to every Monday.
- monthly() : self
- Set the execution time to once a month.
- november() : self
- Set the execution time to every November.
- october() : self
- Set the execution time to every October.
- onFailure() : self
- Set failure callback
- onlyOne() : self
- This will prevent the Job from overlapping.
- onRetry() : self
- Set retry callback
- onSuccess() : self
- Set success callback
- output() : self
- Set the file/s where to write the output of the job.
- priority() : self
- Set job priority
- retryDelay() : self
- Set retry delay
- run() : bool
- Run the job.
- runInBackground() : bool
- Check if the Job can run in background.
- runWithRetry() : bool
- Run the job with retry support
- saturday() : self
- Set the execution time to every Saturday.
- september() : self
- Set the execution time to every September.
- setQueueId() : self
- Set queue ID
- sunday() : self
- Set the execution time to every Sunday.
- then() : self
- Set a function to be called after job execution.
- thursday() : self
- Set the execution time to every Thursday.
- timeout() : self
- Set job timeout
- toArray() : array<string|int, mixed>
- Convert job to array for serialization
- tuesday() : self
- Set the execution time to every Tuesday.
- wednesday() : self
- Set the execution time to every Wednesday.
- weekly() : self
- Set the execution time to once a week.
- when() : self
- Truth test to define if the job should run if due.
- withMetadata() : self
- Add metadata to the job
- withTags() : self
- Add tags to the job
- calculateRetryDelay() : int
- Calculate retry delay based on strategy
- checkDependencies() : bool
- Check if dependencies are met
- runChainedJobs() : void
- Run chained jobs
- createLockFile() : void
- Create the job lock file.
- emailOutput() : bool
- Email the output of the job, if any.
- exec() : string
- Execute a callable job.
- postRun() : void
- Things to run after job has run
- removeLockFile() : void
- Remove the job lock file.
- validateCronRange() : mixed
- Validate sequence of cron expression.
- validateCronSequence() : array<string|int, mixed>
- Validate sequence of cron expression.
Properties
$chainedJobs
protected
array<string|int, mixed>
$chainedJobs
= []
$dependencies
protected
array<string|int, mixed>
$dependencies
= []
$executionDuration
protected
float
$executionDuration
= 0
$executionStartTime
protected
float
$executionStartTime
$maxAttempts
protected
int
$maxAttempts
= 3
$metadata
protected
array<string|int, mixed>
$metadata
= []
$onFailure
protected
callable|null
$onFailure
$onRetry
protected
callable|null
$onRetry
$onSuccess
protected
callable|null
$onSuccess
$priority
protected
string
$priority
= 'normal'
$queueId
protected
string|null
$queueId
$retryCount
protected
int
$retryCount
= 0
$retryDelay
protected
int
$retryDelay
= 60
$retryStrategy
protected
string
$retryStrategy
= 'exponential'
$tags
protected
array<string|int, mixed>
$tags
= []
$timeout
protected
int
$timeout
= 300
$after
private
callable|null
$after
$args
private
array<string|int, mixed>
$args
= []
$at
private
string
$at
$backlink
private
string|null
$backlink
$before
private
callable|null
$before
$command
private
callable|string
$command
$creationTime
private
DateTime
$creationTime
$emailConfig
private
array<string|int, mixed>
$emailConfig
= []
$emailTo
private
array<string|int, mixed>
$emailTo
= []
$enabled
private
bool
$enabled
$executionTime
private
CronExpression
$executionTime
$id
private
string
$id
$lockFile
private
string
$lockFile
$output
private
string
$output
$outputMode
private
string
$outputMode
$outputTo
private
array<string|int, mixed>
$outputTo
= []
$process
private
Process|null
$process
$returnCode
private
int
$returnCode
= 0
$runInBackground
private
bool
$runInBackground
= true
$successful
private
bool
$successful
= false
$tempDir
private
string
$tempDir
$truthTest
private
bool
$truthTest
= true
$whenOverlapping
private
callable
$whenOverlapping
Methods
__construct()
Create a new Job instance.
public
__construct(string|callable $command[, array<string|int, mixed> $args = [] ][, string|null $id = null ]) : mixed
Parameters
- $command : string|callable
- $args : array<string|int, mixed> = []
- $id : string|null = null
april()
Set the execution time to every April.
public
april([int|string $day = 1 ][, int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $day : int|string = 1
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selfat()
Set the Job execution time.
public
at(string $expression) : self
compo
Parameters
- $expression : string
Return values
selfaugust()
Set the execution time to every August.
public
august([int|string $day = 1 ][, int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $day : int|string = 1
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selfbacklink()
Sets/Gets an option backlink
public
backlink([string|null $link = null ]) : string|null
Parameters
- $link : string|null = null
Return values
string|nullbefore()
Set function to be called before job execution Job object is injected as a parameter to callable function.
public
before(callable $fn) : self
Parameters
- $fn : callable
Return values
selfchain()
Chain another job to run after this one
public
chain(Job $job[, bool $onlyOnSuccess = true ]) : self
Parameters
- $job : Job
- $onlyOnSuccess : bool = true
-
Run only if current job succeeds
Return values
selfconfigure()
Configure the job.
public
configure([array<string|int, mixed> $config = [] ]) : self
Parameters
- $config : array<string|int, mixed> = []
Return values
selfdaily()
Set the execution time to once a day.
public
daily([int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selfdecember()
Set the execution time to every December.
public
december([int|string $day = 1 ][, int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $day : int|string = 1
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selfdependsOn()
Add job dependency
public
dependsOn(string $jobId) : self
Parameters
- $jobId : string
Return values
selfemail()
Set the emails where the output should be sent to.
public
email(string|array<string|int, mixed> $email) : self
The Job should be set to write output to a file for this to work.
Parameters
- $email : string|array<string|int, mixed>
Return values
selfeveryMinute()
Set the execution time to every minute.
public
everyMinute() : self
Return values
selffebruary()
Set the execution time to every February.
public
february([int|string $day = 1 ][, int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $day : int|string = 1
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selffinalize()
Finish up processing the job
public
finalize() : void
friday()
Set the execution time to every Friday.
public
friday([int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selffromArray()
Create job from array
public
static fromArray(array<string|int, mixed> $data) : self
Parameters
- $data : array<string|int, mixed>
Return values
selfgetArguments()
Get optional arguments
public
getArguments() : string|null
Return values
string|nullgetAt()
Get the cron 'at' syntax for this job
public
getAt() : string
Return values
stringgetCommand()
Get the command
public
getCommand() : Closure|string
Return values
Closure|stringgetCronExpression()
public
getCronExpression() : CronExpression
Return values
CronExpressiongetEnabled()
Get the status of this job
public
getEnabled() : bool
Return values
boolgetExecutionTime()
Get execution time in seconds
public
getExecutionTime() : float
Return values
floatgetId()
Get the Job id.
public
getId() : string
Return values
stringgetMaxAttempts()
Get maximum retry attempts
public
getMaxAttempts() : int
Return values
intgetMetadata()
Get job metadata
public
getMetadata([string|null $key = null ]) : mixed
Parameters
- $key : string|null = null
getOutput()
Get the job output.
public
getOutput() : mixed
getPriority()
Get job priority
public
getPriority() : string
Return values
stringgetProcess()
Get process (for background jobs)
public
getProcess() : Process|null
Return values
Process|nullgetQueueId()
Get queue ID
public
getQueueId() : string|null
Return values
string|nullgetRawArguments()
Get raw arguments (array or string)
public
getRawArguments() : array<string|int, mixed>|string
Return values
array<string|int, mixed>|stringgetRetryCount()
Get current retry count
public
getRetryCount() : int
Return values
intgetTags()
Get job tags
public
getTags() : array<string|int, mixed>
Return values
array<string|int, mixed>hasTag()
Check if job has a specific tag
public
hasTag(string $tag) : bool
Parameters
- $tag : string
Return values
boolhourly()
Set the execution time to every hour.
public
hourly([int|string $minute = 0 ]) : self
Parameters
- $minute : int|string = 0
Return values
selfinForeground()
Force the Job to run in foreground.
public
inForeground() : $this
Return values
$thisisDue()
Check if the Job is due to run.
public
isDue([DateTime|null $date = null ]) : bool
It accepts as input a DateTime used to check if the job is due. Defaults to job creation time. It also default the execution time if not previously defined.
Parameters
- $date : DateTime|null = null
Return values
boolisOverlapping()
Check if the Job is overlapping.
public
isOverlapping() : bool
Return values
boolisSuccessful()
Get the status of the last run for this job
public
isSuccessful() : bool
Return values
booljanuary()
Set the execution time to every January.
public
january([int|string $day = 1 ][, int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $day : int|string = 1
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selfjuly()
Set the execution time to every July.
public
july([int|string $day = 1 ][, int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $day : int|string = 1
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selfjune()
Set the execution time to every June.
public
june([int|string $day = 1 ][, int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $day : int|string = 1
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selfmarch()
Set the execution time to every March.
public
march([int|string $day = 1 ][, int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $day : int|string = 1
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selfmaxAttempts()
Set maximum retry attempts
public
maxAttempts(int $attempts) : self
Parameters
- $attempts : int
Return values
selfmay()
Set the execution time to every May.
public
may([int|string $day = 1 ][, int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $day : int|string = 1
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selfmonday()
Set the execution time to every Monday.
public
monday([int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selfmonthly()
Set the execution time to once a month.
public
monthly([int|string $month = '*' ][, int|string $day = 1 ][, int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $month : int|string = '*'
- $day : int|string = 1
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selfnovember()
Set the execution time to every November.
public
november([int|string $day = 1 ][, int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $day : int|string = 1
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selfoctober()
Set the execution time to every October.
public
october([int|string $day = 1 ][, int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $day : int|string = 1
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selfonFailure()
Set failure callback
public
onFailure(callable $callback) : self
Parameters
- $callback : callable
Return values
selfonlyOne()
This will prevent the Job from overlapping.
public
onlyOne([string|null $tempDir = null ][, callable|null $whenOverlapping = null ]) : self
It prevents another instance of the same Job of being executed if the previous is still running. The job id is used as a filename for the lock file.
Parameters
- $tempDir : string|null = null
-
The directory path for the lock files
- $whenOverlapping : callable|null = null
-
A callback to ignore job overlapping
Return values
selfonRetry()
Set retry callback
public
onRetry(callable $callback) : self
Parameters
- $callback : callable
Return values
selfonSuccess()
Set success callback
public
onSuccess(callable $callback) : self
Parameters
- $callback : callable
Return values
selfoutput()
Set the file/s where to write the output of the job.
public
output(string|array<string|int, mixed> $filename[, bool $append = false ]) : self
Parameters
- $filename : string|array<string|int, mixed>
- $append : bool = false
Return values
selfpriority()
Set job priority
public
priority(string $priority) : self
Parameters
- $priority : string
-
'high', 'normal', or 'low'
Return values
selfretryDelay()
Set retry delay
public
retryDelay(int $seconds[, string $strategy = 'exponential' ]) : self
Parameters
- $seconds : int
- $strategy : string = 'exponential'
-
'linear' or 'exponential'
Return values
selfrun()
Run the job.
public
run() : bool
Return values
boolrunInBackground()
Check if the Job can run in background.
public
runInBackground() : bool
Return values
boolrunWithRetry()
Run the job with retry support
public
runWithRetry() : bool
Return values
boolsaturday()
Set the execution time to every Saturday.
public
saturday([int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selfseptember()
Set the execution time to every September.
public
september([int|string $day = 1 ][, int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $day : int|string = 1
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selfsetQueueId()
Set queue ID
public
setQueueId(string $queueId) : self
Parameters
- $queueId : string
Return values
selfsunday()
Set the execution time to every Sunday.
public
sunday([int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selfthen()
Set a function to be called after job execution.
public
then(callable $fn[, bool $runInBackground = false ]) : self
By default this will force the job to run in foreground because the output is injected as a parameter of this function, but it could be avoided by passing true as a second parameter. The job will run in background if it meets all the other criteria.
Parameters
- $fn : callable
- $runInBackground : bool = false
Return values
selfthursday()
Set the execution time to every Thursday.
public
thursday([int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selftimeout()
Set job timeout
public
timeout(int $seconds) : self
Parameters
- $seconds : int
Return values
selftoArray()
Convert job to array for serialization
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>tuesday()
Set the execution time to every Tuesday.
public
tuesday([int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selfwednesday()
Set the execution time to every Wednesday.
public
wednesday([int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selfweekly()
Set the execution time to once a week.
public
weekly([int|string $weekday = 0 ][, int|string $hour = 0 ][, int|string $minute = 0 ]) : self
Parameters
- $weekday : int|string = 0
- $hour : int|string = 0
- $minute : int|string = 0
Return values
selfwhen()
Truth test to define if the job should run if due.
public
when(callable $fn) : self
Parameters
- $fn : callable
Return values
selfwithMetadata()
Add metadata to the job
public
withMetadata(string $key, mixed $value) : self
Parameters
- $key : string
- $value : mixed
Return values
selfwithTags()
Add tags to the job
public
withTags(array<string|int, mixed> $tags) : self
Parameters
- $tags : array<string|int, mixed>
Return values
selfcalculateRetryDelay()
Calculate retry delay based on strategy
protected
calculateRetryDelay(int $attempt) : int
Parameters
- $attempt : int
Return values
intcheckDependencies()
Check if dependencies are met
protected
checkDependencies() : bool
Return values
boolrunChainedJobs()
Run chained jobs
protected
runChainedJobs(bool $success) : void
Parameters
- $success : bool
-
Whether the current job succeeded
createLockFile()
Create the job lock file.
private
createLockFile([mixed $content = null ]) : void
Parameters
- $content : mixed = null
emailOutput()
Email the output of the job, if any.
private
emailOutput() : bool
Return values
boolexec()
Execute a callable job.
private
exec() : string
Tags
Return values
stringpostRun()
Things to run after job has run
private
postRun() : void
removeLockFile()
Remove the job lock file.
private
removeLockFile() : void
validateCronRange()
Validate sequence of cron expression.
private
validateCronRange(int|string|null $value, int $min, int $max) : mixed
Parameters
- $value : int|string|null
- $min : int
- $max : int
validateCronSequence()
Validate sequence of cron expression.
private
validateCronSequence([int|string|null $minute = null ][, int|string|null $hour = null ][, int|string|null $day = null ][, int|string|null $month = null ][, int|string|null $weekday = null ]) : array<string|int, mixed>
Parameters
- $minute : int|string|null = null
- $hour : int|string|null = null
- $day : int|string|null = null
- $month : int|string|null = null
- $weekday : int|string|null = null