FRED™  3.0
FRED™: Framework for Rapid and Easy Development
Worker Class Reference
Inheritance diagram for Worker:
Component Thing

Public Member Functions

 schedule ($class_name, $config=null, $time=null, $interval=null, $max_time=null)
 Add a job to the queue. More...
 
 delete ($id)
 Delete a scheduled job from the queue. More...
 
 instant ($class_name, $config=null, $timer_id=null)
 Run a job instantly. More...
 
 execute ($id=null)
 Execute the worker / process the scheduled jobs. More...
 
- Public Member Functions inherited from Component
 __construct ($fred, $config=null)
 
 __destruct ()
 
 clientConfig ()
 Public configuration. More...
 
 config ($key, $default=null)
 Retrieve a config value. More...
 
 ping ()
 Ping function. More...
 
 filemtime ($filename)
 Filemtime with session cache. More...
 
 component ($name)
 Get a component (local or default). More...
 
 components (... $names)
 Get multiple components in an array. More...
 
- Public Member Functions inherited from Thing
 propertyExists ($property)
 Check if a property exists (public or published). More...
 
 constants ($prefix=null)
 Return all constants. More...
 
 get ($key)
 Get one or more properties. More...
 
 set ($key, $value=null)
 Set one or more properties. More...
 
 __get ($key)
 
 __set ($key, $value)
 

Data Fields

 $classNameAlias = []
 Job class name aliasses (key = alias, value = class name). More...
 
 $parallelCommand = null
 Command for executing a single job as a seperate process (asterisk is replaced with job. More...
 
 $timeLimit = 60
 Default time limit for a job (seconds). More...
 
 $minTime = 10
 Keep processing for at least this amount of time (seconds; even when there are no more jobs. More...
 
 $sleepTime = 0.5
 Time to sleep when there are no more jobs scheduled (but still within minTime; seconds). More...
 
 $maxTime = 300
 Halt the processig of jobs after this time (seconds; even when there are more jobs scheduled). More...
 
 $maxJobs = 100
 Halt the processig of jobs after this amount of jobs processed (even when there are more jobs. More...
 
 $defaultOverduePeriod = '+1 hour'
 Default overdue period for jobs that do not have a rescheduling interval. More...
 
 $logTimerPrio = null
 Log the begin and end times of a job with this (custom) prio. More...
 
- Data Fields inherited from Component
 $filemtimeTtl = 0
 
- Data Fields inherited from Thing
const HIDDEN = 0
 Property is hidden. More...
 
const READABLE = 1
 Property is readable. More...
 
const WRITEABLE = 2
 Property is writeable. More...
 
const READWRITE = 3
 Property is readable and writeable. More...
 

Protected Member Functions

 transClassName ($class_name)
 Translate a job class name. More...
 
 create ($class_name, $id, $config=null, $time=null, $interval=null, $max_time=null)
 Create a job object. More...
 
 next ($id=null)
 Next scheduled job to execute. More...
 
 lock ($job)
 Lock a job. More...
 
 unlock ($job)
 Unlock a job. More...
 
 reschedule ($job, $time=null)
 Reschedule a job. More...
 
 ready ($job)
 Mark a job as done. More...
 
 groupCount ($group_id)
 Number of active jobs in a group. More...
 
 checkGroup ($job)
 Check if the group (if any) is within its limit. More...
 
 overdue ()
 Overdue jobs. More...
 
- Protected Member Functions inherited from Component
 init ()
 
 done ()
 
 getSession ()
 
- Protected Member Functions inherited from Thing
 publish ($property, $visibility=self::READABLE)
 Publish a property (or hide it again). More...
 
 alias ($alias, $property, $object=null)
 Define an alias for a property (of another object). More...
 
 configure ($config)
 Configure the object. More...
 
 _get ($key)
 Default getter if no specific setter is defined, and the property is also not published (readable). More...
 
 _set ($key, $value)
 Default setter if no specific setter is defined, and the property is also not published (writeable). More...
 

Additional Inherited Members

- Protected Attributes inherited from Component
 $_fred = null
 
 $_config = null
 
 $_name = null
 
 $_components = []
 Local components (key = component name, value = component). More...
 
 $_session = null
 
- Protected Attributes inherited from Thing
 $_published = []
 Published properties (key = name of property, value = visibility). More...
 
 $_aliases = []
 Alias properties (key = alias, value = [object,property]). More...
 

Detailed Description

Definition at line 5 of file Worker.php.

Member Function Documentation

◆ checkGroup()

checkGroup (   $job)
protected

Check if the group (if any) is within its limit.

Parameters
\\Rsi\\Fred\\Worker\\Job$jobJob.
Returns
bool True when OK.

Definition at line 125 of file Worker.php.

◆ create()

create (   $class_name,
  $id,
  $config = null,
  $time = null,
  $interval = null,
  $max_time = null 
)
protected

Create a job object.

Parameters
string$class_nameClass name for the job.
string$idUnique ID for the job.
array$configConfiguration options (key-value pairs) for the job.
int$timeTime to run the job (null for as soon as possible).
string$intervalString that is understood by PHP's strtotime() to reschedule the job after it is finished. Prefix with an '@' to make it relative to the time of finishing (normally it is relative to the planned time).
int$max_timeMaximum time for executing job (seconds).
Returns
\Rsi\Fred\Worker\Job

Definition at line 60 of file Worker.php.

◆ delete()

delete (   $id)

Delete a scheduled job from the queue.

Parameters
string$idJob ID.
Returns
bool True when successful.

Definition at line 46 of file Worker.php.

◆ execute()

execute (   $id = null)

Execute the worker / process the scheduled jobs.

Call his function as often as possible.

Parameters
string$idOnly check this job ID.

Definition at line 141 of file Worker.php.

◆ groupCount()

groupCount (   $group_id)
protected

Number of active jobs in a group.

Parameters
int$group_idGroup ID.
Returns
int Number of active (locked) jobs.

Definition at line 117 of file Worker.php.

◆ instant()

instant (   $class_name,
  $config = null,
  $timer_id = null 
)

Run a job instantly.

Parameters
string$class_nameClass name for the job.
array$configConfiguration options (key-value pairs) for the job.
string$timer_idTimer ID for the job to log to.

Definition at line 69 of file Worker.php.

◆ lock()

lock (   $job)
protected

Lock a job.

Parameters
\\Rsi\\Fred\\Worker\\Job$jobJob to lock.
Returns
bool True if the job has been locked.

Definition at line 85 of file Worker.php.

◆ next()

next (   $id = null)
protected

Next scheduled job to execute.

Parameters
string$idOnly check this job ID.
Returns
\Rsi\Fred\Worker\Job (empty if there is no job to be executed).

Definition at line 77 of file Worker.php.

◆ overdue()

overdue ( )
protected

Overdue jobs.

Jobs that have been locked longer than twice their interval or the default overdue interval.

Returns
array Of \Rsi\Fred\Worker\Job items.

Definition at line 133 of file Worker.php.

◆ ready()

ready (   $job)
protected

Mark a job as done.

Parameters
\\Rsi\\Fred\\Worker\\Job$jobJob.

Definition at line 109 of file Worker.php.

◆ reschedule()

reschedule (   $job,
  $time = null 
)
protected

Reschedule a job.

Parameters
\\Rsi\\Fred\\Worker\\Job$jobJob to reschedule.
int$timeTime to reschedule at (null for as soon as possible).
Returns
bool True if the job has been rescheduled.

Definition at line 102 of file Worker.php.

◆ schedule()

schedule (   $class_name,
  $config = null,
  $time = null,
  $interval = null,
  $max_time = null 
)

Add a job to the queue.

Parameters
string | array$class_nameClass name for the job (or array with group code and class name).
array$configConfiguration options (key-value pairs) for the job.
int$timeTime to run the job (null for as soon as possible).
string$intervalString that is understood by PHP's strtotime() to reschedule the job after it is finished. Prefix with an '@' to make it relative to the time of finishing (normally it is relative to the planned time).
int$max_timeMaximum time for executing job (seconds).
Returns
string Job ID when successful.

Definition at line 38 of file Worker.php.

◆ transClassName()

transClassName (   $class_name)
protected

Translate a job class name.

Parameters
string$class_nameClass name for the job, or an alias.
Returns
string Class name.

Definition at line 25 of file Worker.php.

◆ unlock()

unlock (   $job)
protected

Unlock a job.

Parameters
\\Rsi\\Fred\\Worker\\Job$jobJob to unlock.
Returns
bool True if the job has been unlocked.

Definition at line 93 of file Worker.php.

Field Documentation

◆ $classNameAlias

$classNameAlias = []

Job class name aliasses (key = alias, value = class name).

Definition at line 7 of file Worker.php.

◆ $defaultOverduePeriod

$defaultOverduePeriod = '+1 hour'

Default overdue period for jobs that do not have a rescheduling interval.

Definition at line 17 of file Worker.php.

◆ $logTimerPrio

$logTimerPrio = null

Log the begin and end times of a job with this (custom) prio.

Definition at line 18 of file Worker.php.

◆ $maxJobs

$maxJobs = 100

Halt the processig of jobs after this amount of jobs processed (even when there are more jobs.

Definition at line 15 of file Worker.php.

◆ $maxTime

$maxTime = 300

Halt the processig of jobs after this time (seconds; even when there are more jobs scheduled).

Definition at line 14 of file Worker.php.

◆ $minTime

$minTime = 10

Keep processing for at least this amount of time (seconds; even when there are no more jobs.

Definition at line 11 of file Worker.php.

◆ $parallelCommand

$parallelCommand = null

Command for executing a single job as a seperate process (asterisk is replaced with job.

Definition at line 8 of file Worker.php.

◆ $sleepTime

$sleepTime = 0.5

Time to sleep when there are no more jobs scheduled (but still within minTime; seconds).

Definition at line 13 of file Worker.php.

◆ $timeLimit

$timeLimit = 60

Default time limit for a job (seconds).

Definition at line 10 of file Worker.php.


The documentation for this class was generated from the following file: