30 Dec 2021 13:24:42 UTC
- Distribution: TheSchwartz
- Source (raw)
- Browse (raw)
- How to Contribute
- Testers (1 / 0 / 0)
- KwaliteeBus factor: 2
- 19.24% Coverage
- License: perl_5
- Perl: v5.8.1
- Activity24 month
- Download (53.21KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version++ed by:7 non-PAUSE usersAKIYM Takumi Akiyama 🍙🍙🍙
- TheSchwartz::Job->new( %args )
- TheSchwartz::Job->new_from_array( $funcname, $arg )
- $job->funcname([ $funcname ])
- $job->handle([ $handle ])
- $job->add_failure( $msg )
- $job->set_exit_status( $status )
- $job->did_something([ $value ])
- $job->debug( $msg )
- SEE ALSO
TheSchwartz::Job - jobs for the reliable job queue
my $client = TheSchwartz->new( databases => $DATABASE_INFO ); my $job = TheSchwartz::Job->new_from_array('MyWorker', [ foo => 'bar' ]); $client->insert($job); $job = TheSchwartz::Job->new( funcname => 'MyWorker', uniqkey => 7, arg => [ foo => 'bar' ], ); $client->insert($job);
TheSchwartz::Jobmodels the jobs that are posted to the job queue by your application, then grabbed and performed by your worker processes.
Data::ObjectDrivermodel class. See Data::ObjectDriver::BaseObject.
TheSchwartz::Jobobjects have these possible fields:
The unique numeric identifier for this job. Set automatically when saved.
The numeric identifier for the type of job to perform.
TheSchwartzclients map function names (also known as abilities and worker class names) to these numbers using
Arbitrary state data to supply to the worker process for this job. If specified as a reference, the data is frozen to a blob with the
An arbitrary string identifier used to prevent applications from posting duplicate jobs. At most one with the same
uniqkeyvalue can be posted to a single
insert_timefield is not used.
The UNIX system time after which the job can next be attempted by a worker process. This time stamp is set when a job is first created or is released after a failure.
The UNIX system time after which the job can next be available by a worker process. This time stamp is set when a job is grabbed by a worker process, and reset to
0when is released due to failure to complete the job.
An integer value to specify the priority of the job to be executed; larger numbers mean higher priority. See
prioritizeproperty of TheSchwartz for details.
A string used to discover jobs that can be efficiently pipe-lined with a given job due to some shared resource. For example, for email delivery jobs, the domain of an email address could be used as the
coalescevalue. A worker process could then deliver all the mail queued for a given mail host after connecting to it once.
Returns a new job object with the given data. Members of
%argscan be keyed on any of the fields described above, or
Returns a new job with the given function name (also called ability or worker class), and the scalar or reference
$argfor an argument.
Returns the function name for the given job, after setting it to
$funcname, if specified.
TheSchwartz::JobHandleobject describing this job, after setting it to
$handle, if specified. A job handle is a convenience class for accessing other records related to jobs; as its convenience methods are also available directly from
TheSchwartz::Jobinstances, you will usually not need to work directly with job handles.
Data::ObjectDriverobject driver for accessing the database in which
$jobis stored. See Data::ObjectDriver.
Records and returns a new
TheSchwartz::Errorobject representing a failure to perform
$job, for reason
Returns the exit status specified by the worker that either completed the job or declared it failed permanently. The exit status for a job will be available for a period of time after the job has exited the queue. That time is defined in the job's worker class's
Returns a list of the error messages specified to
add_failure()when a worker failed to perform the given job.
Returns the number of times a worker has grabbed this job, only to fail to complete it.
Records the exit status of the given job as
Returns whether the given job has been completed or failed since it was created or loaded, setting whether it has to
$valuefirst, if specified.
Sets (if given an argument) and returns the value of the was_declined flag for a job object. See also
Sends the given message to the job's
TheSchwartzclient as debug output.
$jobas the current job being performed by its associated
TheSchwartz::Workerclasses should use these methods to update the status of their jobs:
Records that the given job has been fully performed and removes it from the job queue. Completing a job records its exit status as
Records that the worker performing this job failed to complete it, for reason
If workers have not failed to complete the job more times than the maximum number of retries for that type of job, the job will be reattempted after its retry delay has elapsed. The maximum number of retries and the delay before a retry are defined in the job's worker class definition as
If workers have exceeded the maximum number of reattempts for this job, the job's exit status is recorded as
$exit_status, and the job is removed from the queue. If
$exit_statusis not defined or
0, the job will be recorded with an exit status of
1, to indicate a failure.
Records that the worker performing this job failed to complete it, as in
failed(), but that the job should not be reattempted, no matter how many times the job has been attempted before. The job's exit status is thus recorded as
1), and the job is removed from the queue.
Report that the job has been declined for handling at this time, which means that the job will be retried after the next grabbed_until interval, and does not count against the max_retries count.
If $run_after is set then the job will be grabbed_until will be reset and the job will be reconsidered at $run_after, and does not count against the max_retries count.
Atomically replaces the single job
$jobwith the given set of jobs.
This can be used to decompose one "meta job" posted by your application into a set of jobs workers can perform, or to post a job or jobs required to complete the process already partly performed.