Skip to content

Instantly share code, notes, and snippets.

@diegok
Last active August 19, 2016 16:51
Show Gist options
  • Save diegok/b6706b62c6f4ae1b007873078eb0cff1 to your computer and use it in GitHub Desktop.
Save diegok/b6706b62c6f4ae1b007873078eb0cff1 to your computer and use it in GitHub Desktop.
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