Task.phpView Source

Show: PublicProtectedPrivateinherited
Table of Contents
Interface for Danga's Gearman job scheduling system

PHP version 5.1.0+

LICENSE: This source file is subject to the New BSD license that is available through the world-wide-web at the following URI: http://www.opensource.org/licenses/bsd-license.php. If you did not receive a copy of the New BSD License and are unable to obtain it through the web, please send a note to license@php.net so we can mail you a copy immediately.

Author
Joe Stump  
Category
Net  
Copyright
2007-2008 Digg.com, Inc.  
License
New BSD License  
Link
http://pear.php.net/package/Net_Gearman  
Link
http://www.danga.com/gearman/  
Package
ShSo\Net\Gearman  
Version
CVS: $Id$  

\ShSo\Net\Gearman\Task

Package: ShSo\Net\Gearman
Task class for creating ShSo\Net\Gearman tasks
See
ShSo\Net\Gearman\Client  
Author
Joe Stump  
Category
Net  
Copyright
2007-2008 Digg.com, Inc.  
License
New BSD License  
Link
http://www.danga.com/gearman/  
Version
Release: @package_version@  

Constants

>VConstantinteger  JOB_NORMAL = 1
Normal job

Normal jobs are ran against a worker with the result being returned all in the same thread (e.g. Your page will sit there waiting for the job to finish and return it's result).

JOB_NORMAL
integer

JOB_NORMAL

>VConstantinteger  JOB_BACKGROUND = 2
Background job

Background jobs in Gearman are "fire and forget". You can check a job's status periodically, but you can't get a result back from it.

JOB_BACKGROUND
integer

JOB_BACKGROUND

>VConstantinteger  JOB_HIGH = 3
High priority job
JOB_HIGH
integer

JOB_HIGH

>VConstantinteger  JOB_HIGH_BACKGROUND = 4
High priority, background job
JOB_HIGH_BACKGROUND
integer

JOB_HIGH

>VConstantinteger  JOB_LOW = 5
LOW priority job
JOB_LOW
integer

JOB_LOW

>VConstantinteger  JOB_LOW_BACKGROUND = 6
Low priority, background job
JOB_LOW_BACKGROUND
integer

JOB_LOW_BACKGROUND

>VConstantinteger  TASK_COMPLETE = 1
Callback of type complete

The callback provided should be ran when the task has been completed. It will be handed the result of the task as its only argument.

See
 
TASK_COMPLETE
integer

TASK_COMPLETE

>VConstantinteger  TASK_FAIL = 2
Callback of type fail

The callback provided should be ran when the task has been reported to have failed by Gearman. No arguments are provided.

See
 
TASK_FAIL
integer

TASK_FAIL

>VConstantinteger  TASK_STATUS = 3
Callback of type status

The callback provided should be ran whenever the status of the task has been updated. The numerator and denominator are passed as the only two arguments.

See
 
TASK_STATUS
integer

TASK_STATUS

Properties

>VPropertypublicarray $arg = array()
Arguments to pass to function/job
Default valuearray()Details
Type
array
>VPropertyprotectedarray $callback = array(self::TASK_COMPLETE => array(), self::TASK_FAIL => array(), self::TASK_STATUS => array())
Callbacks registered for each state
Default valuearray(self::TASK_COMPLETE => array(), self::TASK_FAIL => array(), self::TASK_STATUS => array())Details
Type
array
See
 
See
 
See
 
See
 
>VPropertypublicboolean $finished = false
Is this task finished?
Default valuefalseDetails
Type
boolean
See
 
See
 
See
 
>VPropertypublicstring $func = ''
The function/job to run
Default value''Details
Type
string
>VPropertypublicstring $handle = ''
Handle returned from job server
Default value''Details
Type
string
See
 
>VPropertypublicobject $result = ''
The result returned from the worker
Default value''Details
Type
object
>VPropertypublicinteger $type = self::JOB_NORMAL
Type of job

Which type of job you wish this task to be ran as. Keep in mind that background jobs are "fire and forget" and DO NOT return results to the job server in a manner that you can actually retrieve.

Default valueself::JOB_NORMALDetails
Type
integer
See
 
See
 
See
 
See
 
See
 
See
 
>VPropertypublicstring $uniq = ''
The unique identifier for this job

Keep in mind that a unique job is only unique to the job server it is submitted to. Gearman servers don't communicate with each other to ensure a job is unique across all workers.

That being said, Gearman does group identical jobs sent to it and runs that job only once. If you send the job Sum with args 1, 2, 3 to the server 10 times in a second Gearman will only run that job once and then return the result 10 times.

Default value''Details
Type
string

Methods

methodpublic__construct(string $func, mixed $arg, string $uniq = null, integer $type = self::JOB_NORMAL) : \ShSo\Net\Gearman\ShSo\Net\Gearman\Task

Constructor

Parameters
NameTypeDescription
$funcstring

Name of job to run

$argmixed

List of arguments for job

$uniqstring

The unique id of the job

$typeinteger

Type of job to run task as

Returns
TypeDescription
\ShSo\Net\Gearman\ShSo\Net\Gearman\Task
Throws
ExceptionDescription
\ShSo\Net\Gearman\ShSo\Net\Gearman\Exception
methodpublicattachCallback(callback $callback, integer $type = self::TASK_COMPLETE) : \ShSo\Net\Gearman\Task

Attach a callback to this task

Parameters
NameTypeDescription
$callbackcallback

A valid PHP callback

$typeinteger

Type of callback

Returns
TypeDescription
\ShSo\Net\Gearman\Task
Throws
ExceptionDescription
\ShSo\Net\Gearman\ShSo\Net\Gearman\ExceptionWhen the callback is invalid.
\ShSo\Net\Gearman\ShSo\Net\Gearman\ExceptionWhen the callback's type is invalid.
Details
Fluent
This method is part of a fluent interface and will return the same instance  
methodpubliccomplete(object $result) : void

Run the complete callbacks

Complete callbacks are passed the name of the job, the handle of the job and the result of the job (in that order).

Parameters
NameTypeDescription
$resultobject

JSON decoded result passed back

Details
See
 
methodpublicfail() : void

Run the failure callbacks

Failure callbacks are passed the task object job that failed

Details
See
 
methodpublicgetCallbacks() : array

Return all callbacks.

Returns
TypeDescription
array
methodpublicstatus(integer $numerator, integer $denominator) : void

Run the status callbacks

Status callbacks are passed the name of the job, handle of the job and the numerator/denominator as the arguments (in that order).

Parameters
NameTypeDescription
$numeratorinteger

The numerator from the status

$denominatorinteger

The denominator from the status

Details
See
 
Documentation was generated by phpDocumentor 2.8.5.