PHP Class PHPDaemon\Core\ComplexJob

Author: Vasily Zorin ([email protected])
Inheritance: implements ArrayAccess, use trait PHPDaemon\Traits\ClassWatchdog, use trait PHPDaemon\Traits\StaticObjectWatchdog
显示文件 Open project: kakserpom/phpdaemon Class Usage Examples

Public Properties

Property Type Description
$jobs Hash of jobs [jobname -> callback, ...]
$jobsNum Number of jobs
$listeners Listeners [callable, ...]
$results Hash of results [jobname -> result, ...]
$resultsNum Number of results
$state Current state
$vars

Protected Properties

Property Type Description
$backlog
$keep
$maxConcurrency
$more
$moreFirstFlag

Public Methods

Method Description
__construct ( callable $cb = null ) Constructor
__invoke ( mixed $name = null, callable $cb = null ) : void Adds new job or calls execute() method
addJob ( string $name, callable $cb ) : boolean Adds job
addListener ( callable $cb ) : void Adds listener
checkQueue ( ) : void Called automatically. Checks whether if the queue is full. If not, tries to pull more jobs from backlog and 'more'
cleanup ( ) : void Clean up
execute ( ) : void Runs the job
getResult ( string $jobname ) : mixed Get result
getResults ( ) : array Returns associative array of results
hasCompleted ( ) : boolean Has completed?
isQueueFull ( ) : boolean Returns whether or not the queue is full (maxConcurrency option exceed)
keep ( boolean $keep = true ) : void Keep
maxConcurrency ( integer $n ) : this Sets a limit of simultaneously executing tasks
more ( callable $cb = null ) : this Sets a callback which is going to be fired always when we have a room for more jobs
offsetExists ( string $j ) : boolean Handler of isset($job[$name])
offsetGet ( string $j ) : mixed Handler of $job[$name]
offsetSet ( string $j, mixed $v ) : void Handler of $job[$name] = $value
offsetUnset ( string $j ) : void Handler of unset($job[$name])
setResult ( string $jobname, mixed $result = null ) : boolean Set result

Protected Methods

Method Description
checkIfAllReady ( ) : void Checks if all jobs are ready

Method Details

__construct() public method

Constructor
public __construct ( callable $cb = null )
$cb callable Listener

__invoke() public method

Adds new job or calls execute() method
public __invoke ( mixed $name = null, callable $cb = null ) : void
$name mixed
$cb callable
return void

addJob() public method

Adds job
public addJob ( string $name, callable $cb ) : boolean
$name string Job name
$cb callable Callback
return boolean Success

addListener() public method

Adds listener
public addListener ( callable $cb ) : void
$cb callable Callback
return void

checkIfAllReady() protected method

Checks if all jobs are ready
protected checkIfAllReady ( ) : void
return void

checkQueue() public method

Called automatically. Checks whether if the queue is full. If not, tries to pull more jobs from backlog and 'more'
public checkQueue ( ) : void
return void

cleanup() public method

Clean up
public cleanup ( ) : void
return void

execute() public method

Runs the job
public execute ( ) : void
return void

getResult() public method

Get result
public getResult ( string $jobname ) : mixed
$jobname string Job name
return mixed Result or null

getResults() public method

Returns associative array of results
public getResults ( ) : array
return array

hasCompleted() public method

Has completed?
public hasCompleted ( ) : boolean
return boolean

isQueueFull() public method

Returns whether or not the queue is full (maxConcurrency option exceed)
public isQueueFull ( ) : boolean
return boolean

keep() public method

Keep
public keep ( boolean $keep = true ) : void
$keep boolean Keep?
return void

maxConcurrency() public method

Sets a limit of simultaneously executing tasks
public maxConcurrency ( integer $n ) : this
$n integer Natural number or -1 (no limit)
return this

more() public method

Sets a callback which is going to be fired always when we have a room for more jobs
public more ( callable $cb = null ) : this
$cb callable Callback
return this

offsetExists() public method

Handler of isset($job[$name])
public offsetExists ( string $j ) : boolean
$j string Job name
return boolean

offsetGet() public method

Handler of $job[$name]
public offsetGet ( string $j ) : mixed
$j string Job name
return mixed

offsetSet() public method

Handler of $job[$name] = $value
public offsetSet ( string $j, mixed $v ) : void
$j string Job name
$v mixed Job result
return void

offsetUnset() public method

Handler of unset($job[$name])
public offsetUnset ( string $j ) : void
$j string Job name
return void

setResult() public method

Set result
public setResult ( string $jobname, mixed $result = null ) : boolean
$jobname string Job name
$result mixed Result
return boolean

Property Details

$backlog protected_oe property

protected $backlog

$jobs public_oe property

Hash of jobs [jobname -> callback, ...]
public $jobs

$jobsNum public_oe property

Number of jobs
public $jobsNum

$keep protected_oe property

protected $keep

$listeners public_oe property

Listeners [callable, ...]
public $listeners

$maxConcurrency protected_oe property

protected $maxConcurrency

$more protected_oe property

protected $more

$moreFirstFlag protected_oe property

protected $moreFirstFlag

$results public_oe property

Hash of results [jobname -> result, ...]
public $results

$resultsNum public_oe property

Number of results
public $resultsNum

$state public_oe property

Current state
public $state

$vars public_oe property

public $vars