Skip to content

Instantly share code, notes, and snippets.

@prg
Created March 6, 2017 15:26
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 prg/5cec40f198b8a0bd9bceaac8185aacd0 to your computer and use it in GitHub Desktop.
Save prg/5cec40f198b8a0bd9bceaac8185aacd0 to your computer and use it in GitHub Desktop.
Minion::Notifier
sub websocket {
my $c = shift;
$c->minion->backend->pg->pubsub->json('foo')->listen(foo => sub {
my ($pubsub, $payload) = @_;
my $job = $c->minion->job($payload->{id});
$c->send({ json => $job->info });
});
}
sub register {
my ($self, $app, $args) = @_;
my $pg = Mojo::Pg->new('postgresql://<user>:<pw>@/test');
$app->minion->on(enqueue => sub {
my ($minion, $id) = @_;
$pg->pubsub->json('foo')->notify('foo' => { id => $id, message => 'enqueue' });
});
$app->minion->on(worker => sub {
my ($minion, $worker) = @_;
$worker->on(dequeue => sub {
my ($w, $job) = @_;
my $id = $job->id;
$pg->pubsub->json('foo')->notify('foo' => { id => $id, message => 'dequeue' });
$job->on(finished => sub {
$pg->pubsub->json('foo')->notify('foo' => { id => $id, message => 'finished' });
});
$job->on(failed => sub {
$pg->pubsub->json('foo')->notify('foo' => { id => $id, message => 'failed' });
});
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment