1TheSchwartz::Worker(3pmU)ser Contributed Perl DocumentatiTohneSchwartz::Worker(3pm)
2
3
4

NAME

6       TheSchwartz::Worker - superclass for defining task behavior
7

SYNOPSIS

9           package MyWorker;
10           use base qw( TheSchwartz::Worker );
11
12           sub work {
13               my $class = shift;
14               my TheSchwartz::Job $job = shift;
15
16               print "Workin' hard or hardly workin'? Hyuk!!\n";
17
18               $job->completed();
19           }
20
21
22           package main;
23
24           my $client = TheSchwartz->new( databases => $DATABASE_INFO );
25           $client->can_do('MyWorker');
26           $client->work();
27

DESCRIPTION

29       TheSchwartz::Worker objects are the salt of the reliable job queuing
30       earth.  The behavior required to perform posted jobs are defined in
31       sub-classes of TheSchwartz::Worker. These sub-classes are named for the
32       ability required of a "TheSchwartz" client to do the job, so that the
33       clients can dispatch automatically to the appropriate worker routine.
34
35       Because jobs can be performed by any machine running code for capable
36       worker classes, "TheSchwartz::Worker"s are generally stateless. All
37       mutable state is stored in the "TheSchwartz::Job" objects. This means
38       all "TheSchwartz::Worker" methods are class methods, and
39       "TheSchwartz::Worker" classes are generally never instantiated.
40

SUBCLASSING

42       Define and customize how a job is performed by overriding these methods
43       in your subclass:
44
45   "$class->work( $job )"
46       Performs the job that required ability $class. Override this method to
47       define how to do the job you're defining.
48
49       Note that will need to call "$job->completed()" or "$job->failed()" as
50       appropriate to indicate success or failure. See TheSchwartz::Job.
51
52   "$class->max_retries( $job )"
53       Returns the number of times workers should attempt the given job. After
54       this many tries, the job is marked as completed with errors (that is, a
55       "TheSchwartz::ExitStatus" is recorded for it) and removed from the
56       queue. By default, returns 0.
57
58   "$class->retry_delay( $num_failures )"
59       Returns the number of seconds after a failure workers should wait until
60       reattempting a job that has already failed $num_failures times. By
61       default, returns 0.
62
63   "$class->keep_exit_status_for()"
64       Returns the number of seconds to allow a "TheSchwartz::ExitStatus"
65       record for a job performed by this worker class to exist. By default,
66       returns 0.
67
68   "$class->grab_for()"
69       Returns the number of seconds workers of this class will claim a
70       grabbed a job.  That is, returns the length of the timeout after which
71       other workers will decide a worker that claimed a job has crashed or
72       faulted without marking the job failed. Jobs that are marked as failed
73       by a worker are also marked for immediate retry after a delay indicated
74       by "retry_delay()".
75

USAGE

77   "$class->grab_job( $client )"
78       Finds and claims a job for workers with ability $class, using
79       "TheSchwartz" client $client. This job can then be passed to "work()"
80       or "work_safely()" to perform it.
81
82   "$class->work_safely( $job )"
83       Performs the job associated with the worker's class name. If an error
84       is thrown while doing the job, the job is appropriately marked as
85       failed, unlike when calling "work()" directly.
86
87
88
89perl v5.30.0                      2019-08-11          TheSchwartz::Worker(3pm)
Impressum