Skip to content

dim0xff/p5-Mojolicious-Plugin-Minion-Tasks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

Mojolicious::Plugin::Minion::Tasks - Auto-register Minion tasks from modules by provided namespace

SYNOPSIS

# In your app.pl
use Mojolicious::Lite;

plugin 'Minion'        => {...};
plugin 'Minion::Tasks' => {
    namespace         => 'MyApp::Task',
    task_defaults     => {},
    'Upload::Picture' => {
        quality => 95,
        resize  => '2048x2048'
    },
};

post '/upload/image' => sub {
    my $c = shift;

    my $upload = $c->req->upload('file');
    $upload->move_to('/tmp/temp.file');

    $c->minion->enqueue(
        upload_picture => [ filename => '/tmp/temp.file' ]
    );

    $self->render( json => { status => 'queued' } );
};



# In MyApp/Task/Upload/Picture.pm
package MyApp::Task::Upload::Picture;
use Mojo::Base -base;

has [qw(app config)];

sub name {'first_second'}

sub process {
    my ( $self, $job, %args ) = @_;

    my $image = somehow_read_image_file( $args{filename} );

    $image->resize_to(   $self->config->{resize}  );
    $image->set_quality( $self->config->{quality} );

    # ...

    $job->finish;
}

1;

DESCRIPTION

Allow you to define and auto register Minion tasks from your task modules.

Each task needs configuration which could be provided via default config or per-task config.

Per-task configuration could be provided via HASH:

Task::Module => {
    key => value,
    ...
}

If Task::Module presents in several namespaces, it is possible to provide config per namespace:

namespace => ['MyApp::Task', 'OtherApp::Task', 'AnotherOne']
'File::Upload' => {
    'MyApp::Task'    => { ... },
    'OtherApp::Task' => { ... },

    default_key => default_value,
    ...
}
# Here AnotherOne::File::Upload will get next config:
# {
#   'MyApp::Task'    => { ... },
#   'OtherApp::Task' => { ... },
#
#   default_key => default_value,
#   ...
# }

AUTHOR

Dmitry "dim0xff" Latin <[email protected]>

COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by Dmitry Latin.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

About

Auto-register Minion tasks from modules by provided namespace

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages