<commit_before>package Mojolicious::Plugin::Minion;
use Mojo::Base 'Mojolicious::Plugin';

use Minion;
use Scalar::Util 'weaken';

sub register {
  my ($self, $app, $conf) = @_;

  push @{$app->commands->namespaces}, 'Minion::Command';

  my $minion = Minion->new;
  $minion->mango->from_string($conf->{uri}) if $conf->{uri};
  weaken $minion->app($app)->{app};
  $app->helper(minion => sub {$minion});
}

1;

=encoding utf8

=head1 NAME

Mojolicious::Plugin::Minion - Minion job queue plugin

=head1 SYNOPSIS

  # Mojolicious
  $self->plugin(Minion => {uri => 'mongodb://127.0.0.1:27017'});

  # Mojolicious::Lite
  plugin Minion => {uri => 'mongodb://127.0.0.1:27017'};<commit_msg>more plugin examples<commit_after>package Mojolicious::Plugin::Minion;
use Mojo::Base 'Mojolicious::Plugin';

use Minion;
use Scalar::Util 'weaken';

sub register {
  my ($self, $app, $conf) = @_;

  push @{$app->commands->namespaces}, 'Minion::Command';

  my $minion = Minion->new;
  $minion->mango->from_string($conf->{uri}) if $conf->{uri};
  weaken $minion->app($app)->{app};
  $app->helper(minion => sub {$minion});
}

1;

=encoding utf8

=head1 NAME

Mojolicious::Plugin::Minion - Minion job queue plugin

=head1 SYNOPSIS

  # Mojolicious
  $self->plugin(Minion => {uri => 'mongodb://127.0.0.1:27017'});

  # Mojolicious::Lite
  plugin Minion => {uri => 'mongodb://127.0.0.1:27017'};

  # Add tasks to your application
  app->minion->add_task(slow_log => sub {
    my ($job, $msg) = @_;
    sleep 5;
    $job->app->log->debug(qq{Received message "$msg".});
  });

  # Start jobs from anywhere in your application
  $c->minion->enqueue(slow_log => ['test 123']);

  # Perform jobs in your application tests
  $t->get_ok('/start_job')->status_is(200);
  my $worker = $t->app->minion->worker;
  $worker->all_jobs;
{'fraction_non_alphanumeric': 0.20222222222222222, 'fraction_numerical': 0.03277777777777778, 'mean_word_length': 4.474164133738602, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3691487', 'n_tokens_mistral': 732, 'n_tokens_neox': 687, 'n_words': 139}