From d3300aa253729ac92dd17c1871cdd2e9102c1f47 Mon Sep 17 00:00:00 2001 From: franck cuny Date: Mon, 28 Jun 2010 08:40:54 +0200 Subject: interval and queue_name from config --- lib/presque/worker.pm | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/presque/worker.pm b/lib/presque/worker.pm index d3e9a0e..cd6e3fc 100644 --- a/lib/presque/worker.pm +++ b/lib/presque/worker.pm @@ -18,8 +18,30 @@ with qw/ presque::worker::Role::Context presque::worker::Role::Logger/; -has queue_name => (is => 'ro', isa => 'Str', required => 1); -has interval => (is => 'ro', isa => 'Int', lazy => 1, default => 1); +has queue_name => ( + is => 'rw', + isa => 'Str', + lazy => 1, + default => sub { + my $self = shift; + if ($self->context->{queue_name}) { + return $self->context->{queue_name}; + } + die "queue_name is missing!"; + } +); +has interval => ( + is => 'rw', + isa => 'Int', + lazy => 1, + default => sub { + my $self = shift; + if ($self->context->{interval}) { + return $self->context->{interval}; + } + return 1; + } +); has _fail_method => ( is => 'rw', isa => 'Bool', @@ -47,6 +69,7 @@ has rest_client => ( Net::Presque->new(api_base_url => $self->context->{rest}->{url}); $client; }, + handles => { pull => 'fetch_job', retry_job => 'failed_job', @@ -67,7 +90,7 @@ sub start { while (!$self->shut_down) { my $job = try { - $self->pull(queue_name => '', worker_id => $self->worker_id); + $self->pull(queue_name => $self->queue_name, worker_id => $self->worker_id); }; $job ? $self->work($job) : $self->idle(); } -- cgit 1.4.1