Share Config and Minion tasks with Commands

92 views
Skip to first unread message

Luc didry

unread,
Feb 22, 2015, 10:55:11 AM2/22/15
to mojol...@googlegroups.com
Hello,

I got two questions with Mojolicious::Commands which are almost the same.

1. Is there a way to share the config between a mojolicious app and a custom command? I use the Config plugin in my application and I successfully did the same in my custom command, but I have some default values in my config, which I put when I add the plugin :

$self->plugin('Config', default => {foo => bar});

Using the plugin twice means that I have to rewrite the default values twice if I want to change them.

Is there something like $self->app->load_config_from_app or a plugin or anything that can make me write things only one time ?

2. I use the Minion plugin in my app. I want to use it in my command too. Is there a way to use in my command the tasks I added in my app ?

By the way : Minion is really great and Mojo::Pg too! The migration tool is soooooo useful! Thanks a lot :-) (and for Mojolicious too, of course :D)
--
Luc
http://www.fiat-tux.fr/
Internet n'est pas compliqué, Internet est ce que vous en faites.

jay m

unread,
Feb 23, 2015, 10:58:49 AM2/23/15
to mojol...@googlegroups.com, l...@didry.org

your custom command will automatically use your app's config if it's run from the app script, e.g. 

> ./script/myapp dumpconfig -m production

you probably want to add this to your app startup so you can define app-specific custom commands by just dropping them in the Command dir
  push @{$self->commands->namespaces}, 'MyApp::Command';

and then put your custom commands in lib/MyApp/Command, for example

package MyApp::Command::dumpconfig;
use Mojo::Base 'Mojolicious::Command';

has description
=> 'dump mode-specific config to stdout';
# here's what you'll get from -h option
has usage      
=> "Usage: ./script/mojo dumpconfig [-m <mode>]\n";

sub run {
   
my $self=shift;

   
my $app = $self->app;
    say $app
->dumper($app->config);;
}
1;

Luc didry

unread,
Feb 23, 2015, 11:08:28 AM2/23/15
to mojol...@googlegroups.com
Le lundi 23 février 2015, 07:58:49 jay m a écrit :
>
> your custom command will automatically use your app's config if it's run
> from the app script, e.g.
>
> > ./script/myapp dumpconfig -m production
>
> you probably want to add this to your app startup so you can define
> app-specific custom commands by just dropping them in the Command dir
> push @{$self->commands->namespaces}, 'MyApp::Command';
>
> and then put your custom commands in lib/MyApp/Command, for example
>
> package MyApp::Command::dumpconfig;
> use Mojo::Base 'Mojolicious::Command';
>
> has description => 'dump mode-specific config to stdout';
> # here's what you'll get from -h option
> has usage => "Usage: ./script/mojo dumpconfig [-m <mode>]\n";
>
> sub run {
> my $self=shift;
>
> my $app = $self->app;
> say $app->dumper($app->config);;
> }
> 1;
>

Frak ! It seems that google groups doesn't like my mailer or doesn't like you if you reply to your own mail.

I wrote this yesterday but it didn't reach the mailing list:
? Please, ignore this : it already works! Seems that I did something stupid in the past (I reused the config plugin in a previous app) or that something changed since I wrote the old app.

> By the way : Minion is really great and Mojo::Pg too! The migration tool is soooooo useful! Thanks a lot (and for Mojolicious too, of course :D)
>

Nope, don't ignore that part.

Mojolicious, the framework that anticipate your needs

@Jay : anyway, thx :-)

Luc didry

unread,
Feb 24, 2015, 10:32:21 AM2/24/15
to mojol...@googlegroups.com
Le dimanche 22 février 2015, 16:55:07 Luc didry a écrit :
> Hello,
>
> I got two questions with Mojolicious::Commands which are almost the same.
>
> 1. Is there a way to share the config between a mojolicious app and a custom command? I use the Config plugin in my application and I successfully did the same in my custom command, but I have some default values in my config, which I put when I add the plugin :
>
> $self->plugin('Config', default => {foo => bar});
>
> Using the plugin twice means that I have to rewrite the default values twice if I want to change them.
>
> Is there something like $self->app->load_config_from_app or a plugin or anything that can make me write things only one time ?
>
> 2. I use the Minion plugin in my app. I want to use it in my command too. Is there a way to use in my command the tasks I added in my app ?
>

? Please, ignore this : it already works! Seems that I did something stupid in the past (I reused the config plugin in a previous app) or that something changed since I wrote the old app.

> By the way : Minion is really great and Mojo::Pg too! The migration tool is soooooo useful! Thanks a lot :-) (and for Mojolicious too, of course :D)
>

Nope, don't ignore that :-)

Mojolicious, the framework that anticipate your needs :D
Reply all
Reply to author
Forward
0 new messages