The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Deeme::Worker - represent a Deeme worker that process jobs

SYNOPSIS

package JobQueue;
use Deeme::Obj 'Deeme::Worker';
use Deeme::Backend::Mango;

# app1.pl
package main;
# Subscribe to events in an application (thread, fork, whatever)
my $worker_tiger = JobQueue->new(backend=> Deeme::Backend::Mango->new(...) ); #or you can just do Deeme->new
$worker_tiger->add(roar => sub {
  my ($worker_tiger, $times) = @_;
  say 'RAWR!' for 1 .. $times;
});

 ...

#then, later in another application
# app2.pl
my $worker_tiger = JobQueue->new(backend=> Deeme::Backend::Mango->new(...));
while(my $Job=$worker_tiger->dequeue("roar")){
  $Job->process(@args);
}

...
#or

my $worker_tiger = JobQueue->new(backend=> Deeme::Backend::Mango->new(...));
while($worker_tiger->dequeue("roar")){
  $worker_tiger->process(@args);
}

#or
$worker_tiger->dequeue_events("roar");
$worker_tiger->process_all(1);

DESCRIPTION

Deeme is a database-agnostic driven event emitter base-class. Deeme::Worker allows you to use deem to act also like a jobqueue.

EVENTS

Deeme::Worker inherits all events from Deeme

METHODS

Deeme::Worker inherits all methods from Deeme and implements the following new ones.

add

$e = $e->add(test1=> sub {...});

Subscribe to "test1" jobqueue.

jobs

$n = $e->jobs('test1');

Returns the number of jobs in the queue

dequeue

$Job = $e->dequeue('test1');

Dequeue a job from the "test1" jobqueue, can be accessible also calling $e-process(@args)>, it has the same effect calling $job-process(@args)> after the dequeuing.

dequeue_event

@Jobs = $e->dequeue_event('test1');

Dequeue all jobs from the "test1" jobqueue;

process

$return=$e->process('foo'); #if already dequeued
$return=$Job->process('foo', 123);

Execute job with provided args.

process_all

my @returns=$e->process_all('foo',1,2);

Process all dequeued jobs with provided args and return an array of return values(corrisponding to the jobs).

DEBUGGING

You can set the DEEME_DEBUG environment variable to get some advanced diagnostics information printed to STDERR.

DEEME_DEBUG=1

AUTHOR

mudler <mudler@dark-lab.net>

COPYRIGHT

Copyright 2014- mudler

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Deeme, Deeme::Backend::Mango, Deeme::Backend::Meerkat, Deeme::Backend::Memory, Mojo::EventEmitter, Mojolicious