Skip to content

Instantly share code, notes, and snippets.

@diegok
Last active August 29, 2015 14:05
Show Gist options
  • Save diegok/46b44a02a60aa4004636 to your computer and use it in GitHub Desktop.
Save diegok/46b44a02a60aa4004636 to your computer and use it in GitHub Desktop.
package Company::Task::Example;
# ABSTRACT: Example task class using moose
sub perform {
my $job = shift;
Company::Task::Example::Run->new( job => $job, %{$job->args->[0]} )->run;
}
package Company::Task::Example:Run;
use Moose;
with 'Company::Task::Role::ResqueJob'; # this provides job related attrs, like access to resque and redis :-)
with 'Company::Task::Role::Config';
has url => ( is => 'ro', required => 1 );
has first_seen => ( is => 'ro', lazy => 1, default => sub{time} );
sub run {
my $self = shift;
if ( $self->first_seen < time-3600 ) {
$self->do_something_with_url;
}
else {
$self->requeue_job;
}
}
#...
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment