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)
 Add a job to the queue. More...
 
 delete ($id)
 Delete a scheduled job from the queue. More...
 
 instant ($class_name, $config=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...
 
 $timeLimit = 60
 Default time limit for a job (seconds). More...
 
 $breakCount = 100
 Halt the processig of job after this amount (even when there are more jobs scheduled). More...
 
 $breakTime = 300
 Halt the processig of job after this time (seconds; even when there are more jobs scheduled). 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)
 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...
 
 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...
 
 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...
 

Detailed Description

Definition at line 5 of file Worker.php.

Member Function Documentation

◆ create()

create (   $class_name,
  $id,
  $config = null,
  $time = null,
  $interval = 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.
Returns
\Rsi\Fred\Worker\Job

Definition at line 50 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 38 of file Worker.php.

◆ execute()

execute (   $id = null)

Execute the worker / process the scheduled jobs.

Call his function as often as possible.

Parameters
string$idSpecific job ID to execute (whether scheduled time has come or not).

Definition at line 114 of file Worker.php.

◆ instant()

instant (   $class_name,
  $config = null 
)

Run a job instantly.

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

Definition at line 58 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 74 of file Worker.php.

◆ next()

next (   $id = null)
protected

Next scheduled job to execute.

Parameters
string$idSpecific job ID to execute (whether scheduled time has come or not).
Returns
\Rsi\Fred\Worker\Job (empty if there is no job to be executed).

Definition at line 66 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 106 of file Worker.php.

◆ ready()

ready (   $job)
protected

Mark a job as done.

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

Definition at line 98 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 91 of file Worker.php.

◆ schedule()

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

Add a job to the queue.

Parameters
string$class_nameClass name 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.
Returns
string Job ID when successful.

Definition at line 30 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 19 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 82 of file Worker.php.

Field Documentation

◆ $breakCount

$breakCount = 100

Halt the processig of job after this amount (even when there are more jobs scheduled).

Definition at line 9 of file Worker.php.

◆ $breakTime

$breakTime = 300

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

Definition at line 10 of file Worker.php.

◆ $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 11 of file Worker.php.

◆ $logTimerPrio

$logTimerPrio = null

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

Definition at line 12 of file Worker.php.

◆ $timeLimit

$timeLimit = 60

Default time limit for a job (seconds).

Definition at line 8 of file Worker.php.


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