diff options
author | franck cuny <franck@lumberjaph.net> | 2010-06-28 08:40:54 +0200 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-06-28 08:40:54 +0200 |
commit | d3300aa253729ac92dd17c1871cdd2e9102c1f47 (patch) | |
tree | 8c3bab89d71390c4143d2402b42ce1bbf152935d /lib | |
parent | logger read from context; more net::presque (diff) | |
download | presque-worker-d3300aa253729ac92dd17c1871cdd2e9102c1f47.tar.gz |
interval and queue_name from config
Diffstat (limited to 'lib')
-rw-r--r-- | lib/presque/worker.pm | 29 |
1 files changed, 26 insertions, 3 deletions
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(); } |