TheSch...:Worker(3pm)
π NAME π
okay so this is TheSchwartz::Worker(3pm) β the header lowkey abbreviates it as TheSch...:Worker(3pm) β from the User Contributed Perl Documentation, and it is literally the superclass for defining task behavior. π
β¨ SYNOPSIS β¨
package MyWorker;
use base qw( TheSchwartz::Worker );
sub work {
my $class = shift;
my TheSchwartz::Job $job = shift;
print "Workin' hard or hardly workin'? Hyuk!!\n";
$job->completed();
}
package main;
my $client = TheSchwartz->new( databases => $DATABASE_INFO );
$client->can_do('MyWorker');
$client->work();
πΈ DESCRIPTION πΈ
Bestie, TheSchwartz::Worker objects are the salt of the reliable job queuing earth. π§β¨ The behavior required to perform posted jobs is defined in sub-classes of TheSchwartz::Worker. These sub-classes are named for the ability required of a TheSchwartz client to do the job, so that the clients can dispatch automatically to the appropriate worker routine. It's giving automatic matching, no cap. π
Because jobs can be performed by any machine running code for capable worker classes, TheSchwartz::Workers are generally stateless. All mutable state is stored in the TheSchwartz::Job objects. This means all TheSchwartz::Worker methods are class methods, and TheSchwartz::Worker classes are generally never instantiated. Main character energy: the class does the work, the object stays unbothered. π¦
π¦ SUBCLASSING π¦
Define and customize how a job is performed by overriding these methods in your subclass: π
π
$class->work( $job )
Performs the job that required ability $class. Override this method to define how to do the job you're defining. This is the main event, the moment, the whole vibe check. β¨
Note that you'll need to call $job->completed() or $job->failed() as appropriate to indicate success or failure. See TheSchwartz::Job. Do not forget this part, bestie β it's literally how the job gets marked. π
π
$class->max_retries( $job )
Returns the number of times workers should attempt the given job. After this many tries, the job is marked as completed with errors (that is, a TheSchwartz::ExitStatus is recorded for it) and removed from the queue. By default, returns 0. So yeah, default is zero retries β iconic minimalism. π
π
$class->retry_delay( $num_failures )
Returns the number of seconds after a failure workers should wait until reattempting a job that has already failed $num_failures times. By default, returns 0. Patience is a virtue, and the default patience is zero. β³
π
$class->keep_exit_status_for()
Returns the number of seconds to allow a TheSchwartz::ExitStatus record for a job performed by this worker class to exist. By default, returns 0. Keep those receipts for exactly as long as you say, periodt. π§Ύ
π
$class->grab_for()
Returns the number of seconds workers of this class will claim a grabbed job for. That is, returns the length of the timeout after which other workers will decide a worker that claimed a job has crashed or faulted without marking the job failed. Jobs that are marked as failed by a worker are also marked for immediate retry after a delay indicated by retry_delay(). Translation: this is the βhow long until we assume something went sidewaysβ timer, and failed jobs get their retry glow-up after the retry_delay() wait. π₯
π USAGE π
π
$class->grab_job( $client )
Finds and claims a job for workers with ability $class, using TheSchwartz client $client. This job can then be passed to work() or work_safely() to perform it. Grab it, then hand it off to the actual doing-the-job part. π«Ά
π
$class->work_safely( $job )
Performs the job associated with the worker's class name. If an error is thrown while doing the job, the job is appropriately marked as failed, unlike when calling work() directly. Safety net behavior, lowkey the responsible friend of the group chat. π§
okay that's the whole page, bestie β this one comes from perl v5.42.0, dated 2024-12-31, and the footer also has that cute truncated TheSch...:Worker(3pm) energy. slay, you made it to the end π
β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-TheSchwartz 1.180.0-bp160.1.11 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms