Skip to content

Instantly share code, notes, and snippets.

@preaction
Last active November 22, 2018 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save preaction/bdce415e3098d827eaed3f01b545d9f0 to your computer and use it in GitHub Desktop.
Save preaction/bdce415e3098d827eaed3f01b545d9f0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use Mojolicious::Lite;
use Time::HiRes qw( time );
plugin Minion => {
SQLite => 'sqlite:' . app->home->child('minion.db'),
};
app->minion->add_task(
ping => sub {
my ( $job, $url ) = @_;
my $start = time;
my $tx = $job->app->ua->head( $url );
my $elapsed = time - $start;
$job->app->log->info(
sprintf 'Fetching %s took %.3f seconds', $url, $elapsed
);
$job->finish( $elapsed );
}
);
app->start;
perl minion.pl worker
perl minion.pl job -e ping -a '["http://mojolicious.org"]'
perl minion.pl job -e ping -a '["http://mojolicious.io"]'
perl minion.pl job -e ping -a '["http://google.com"]'
perl minion.pl job -e ping -a '["http://example.com"]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment