Last active
August 19, 2016 16:51
-
-
Save diegok/b6706b62c6f4ae1b007873078eb0cff1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Resque::WorkingClass; | |
use Moose (); | |
use Moose::Exporter; | |
Moose::Exporter->setup_import_methods( | |
with_meta => [ 'perform' ], | |
also => 'Moose', | |
); | |
sub perform { | |
my ($meta, $job) = @_; | |
$meta->add_attribute( job => is => 'ro', handles => [qw/ redis resque /] ) | |
unless $meta->get_attribute('job'); | |
my $job_class = ($meta->linearized_isa)[0]; | |
my $instance = $job_class->new( job => $job, %{$job->args->[0]} ); | |
$instance->can('run') ? $instance->run | |
: die "$job_class is perfrom()ing via Resque::WorkingClass without a run() method!"; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment