Created
November 22, 2018 16:39
-
-
Save richlv/f262475f735b0ecdd7810996a70542ef 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
use strict; | |
use warnings; | |
use Data::Dumper; | |
use Minion; | |
use Minion::Backend::SQLite; | |
my $minion = Minion->new(SQLite => 'sqlite:testing.db'); | |
$minion->on(worker => sub { | |
my ($minion, $worker) = @_; | |
my $id = $worker->id; | |
# This comes from https://mojolicious.org/perldoc/Minion but results in "Use of uninitialized value $id in concatenation (.) or string" - why so? | |
print "Worker $$:$id started.\n"; | |
}); | |
# this seems to be needed so that the sqlite db can be initialised? | |
sleep 2; | |
my $pid = fork(); die "Could not fork: $!" unless defined $pid; if ($pid == 0) { my $worker = $minion->worker(); $worker->status->{jobs} = 12; $worker->run; exit; } | |
# Add tasks | |
$minion->add_task('testtask' => sub { | |
my (@args) = @_; | |
my $job = $args[0]; | |
open(my $fh, '>>', 'test.log'); | |
print $fh Dumper(\@args); | |
close $fh; | |
$job->finish([$args[3], time, 'testvalue']); | |
}); | |
$minion->enqueue('testtask' => [ 'param1', 'param2']); | |
sleep 2; | |
my $stats = $minion->stats; | |
print Dumper($stats); | |
sleep 2; | |
print "minion jobs:\n"; | |
my $minion_jobs = $minion->backend->list_jobs(0, 100); | |
print Dumper($minion_jobs); | |
print "minion tasks:\n"; | |
print Dumper($minion->tasks); | |
kill 1, $pid; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment