how to run function from app from command line?
Hello, I have a big project running on Dancer. This project has some service scripts (to do some cron jobs for example), written as functions in this Dancer app, that should have access to all usual environment (as called from the web functions have), but I need to be able run them from command line. What is the best way to do it? Example: get '/service_func' => {...}; I want to do something like # ./bin/app.pl --run=service_func -- Best Regards, Nick Knutov http://knutov.com ICQ: 272873706 Voice: +7-904-84-23-130
If you have wget or curl installed, you could consider: wget http://localhost:3000/service_function On Sat, Jul 2, 2011 at 2:44 AM, Nick Knutov <mail@knutov.com> wrote:
Hello,
I have a big project running on Dancer. This project has some service scripts (to do some cron jobs for example), written as functions in this Dancer app, that should have access to all usual environment (as called from the web functions have), but I need to be able run them from command line.
What is the best way to do it?
Example:
get '/service_func' => {...};
I want to do something like
# ./bin/app.pl --run=service_func
-- Best Regards, Nick Knutov http://knutov.com ICQ: 272873706 Voice: +7-904-84-23-130 ______________________________**_________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/**cgi-bin/listinfo/dancer-users<http://www.backup-manager.org/cgi-bin/listinfo/dancer-users>
This is a little bit different. It assumes that 1) app is already running 2) and running on port, not unix socket 3) running on known port This is usual not true in my case (well, app is running, but on very different server) I want to run exactly ./bin/app.pl in command line, but how to tell the app to run specified function from the command line? Or should I just add my code to parse $ARGV to app.pl before `dance;` at the end of script? 02.07.2011 8:39, Gurunandan Bhat пишет:
If you have wget or curl installed, you could consider:
wget http://localhost:3000/service_function
On Sat, Jul 2, 2011 at 2:44 AM, Nick Knutov <mail@knutov.com <mailto:mail@knutov.com>> wrote:
Hello,
I have a big project running on Dancer. This project has some service scripts (to do some cron jobs for example), written as functions in this Dancer app, that should have access to all usual environment (as called from the web functions have), but I need to be able run them from command line.
What is the best way to do it?
Example:
get '/service_func' => {...};
I want to do something like
# ./bin/app.pl <http://app.pl> --run=service_func
-- Best Regards, Nick Knutov http://knutov.com ICQ: 272873706 Voice: +7-904-84-23-130 _________________________________________________ Dancer-users mailing list Dancer-users@perldancer.org <mailto:Dancer-users@perldancer.org> http://www.backup-manager.org/__cgi-bin/listinfo/dancer-users <http://www.backup-manager.org/cgi-bin/listinfo/dancer-users>
-- Best Regards, Nick Knutov http://knutov.com ICQ: 272873706 Voice: +7-904-84-23-130
Factor out the functionality you need into another module, then call it both from the Dancer front-end and from a script crafted for the command line. Another approach would be looking at the Dancer's testing modules/functions, they are geared at simulating calls without having a running instance. I'd go for the first approach, anyway. Cheers, Flavio. On Fri, Jul 1, 2011 at 11:14 PM, Nick Knutov <mail@knutov.com> wrote:
Hello,
I have a big project running on Dancer. This project has some service scripts (to do some cron jobs for example), written as functions in this Dancer app, that should have access to all usual environment (as called from the web functions have), but I need to be able run them from command line.
What is the best way to do it?
Example:
get '/service_func' => {...};
I want to do something like
# ./bin/app.pl --run=service_func
-- Best Regards, Nick Knutov http://knutov.com ICQ: 272873706 Voice: +7-904-84-23-130 ______________________________**_________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/**cgi-bin/listinfo/dancer-users<http://www.backup-manager.org/cgi-bin/listinfo/dancer-users>
Well, but I need access to Dancer environment - config, etc. First way does not suited for this, I think. 02.07.2011 13:13, Flavio Poletti пишет:
Factor out the functionality you need into another module, then call it both from the Dancer front-end and from a script crafted for the command line.
Another approach would be looking at the Dancer's testing modules/functions, they are geared at simulating calls without having a running instance. I'd go for the first approach, anyway.
Cheers,
Flavio.
On Fri, Jul 1, 2011 at 11:14 PM, Nick Knutov <mail@knutov.com <mailto:mail@knutov.com>> wrote:
Hello,
I have a big project running on Dancer. This project has some service scripts (to do some cron jobs for example), written as functions in this Dancer app, that should have access to all usual environment (as called from the web functions have), but I need to be able run them from command line.
What is the best way to do it?
Example:
get '/service_func' => {...};
I want to do something like
# ./bin/app.pl <http://app.pl> --run=service_func
-- Best Regards, Nick Knutov http://knutov.com ICQ: 272873706 Voice: +7-904-84-23-130 <tel:%2B7-904-84-23-130> _________________________________________________ Dancer-users mailing list Dancer-users@perldancer.org <mailto:Dancer-users@perldancer.org> http://www.backup-manager.org/__cgi-bin/listinfo/dancer-users <http://www.backup-manager.org/cgi-bin/listinfo/dancer-users>
-- Best Regards, Nick Knutov http://knutov.com ICQ: 272873706 Voice: +7-904-84-23-130
you can put the script in the bin directory and use Dancer qw(:script) in it http://search.cpan.org/~sukria/Dancer-1.3060/lib/Dancer.pm#:script On 2 July 2011 00:14, Nick Knutov <mail@knutov.com> wrote:
Hello,
I have a big project running on Dancer. This project has some service scripts (to do some cron jobs for example), written as functions in this Dancer app, that should have access to all usual environment (as called from the web functions have), but I need to be able run them from command line.
What is the best way to do it?
Example:
get '/service_func' => {...};
I want to do something like
# ./bin/app.pl --run=service_func
-- Best Regards, Nick Knutov http://knutov.com ICQ: 272873706 Voice: +7-904-84-23-130 ______________________________**_________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/**cgi-bin/listinfo/dancer-users<http://www.backup-manager.org/cgi-bin/listinfo/dancer-users>
Thanks! Look like exactly what I need. btw, is there any way to run 'before' in such scripts? I changed before sub {...} to sub _init {...} before sub {_init()}; # in main app app::_init(); # in Dancer ':script' app but this is ugly. 02.07.2011 17:19, Jury Gorky пишет:
you can put the script in the bin directory and use Dancer qw(:script) in it
http://search.cpan.org/~sukria/Dancer-1.3060/lib/Dancer.pm#:script
On 2 July 2011 00:14, Nick Knutov <mail@knutov.com <mailto:mail@knutov.com>> wrote:
Hello,
I have a big project running on Dancer. This project has some service scripts (to do some cron jobs for example), written as functions in this Dancer app, that should have access to all usual environment (as called from the web functions have), but I need to be able run them from command line.
What is the best way to do it?
Example:
get '/service_func' => {...};
I want to do something like
# ./bin/app.pl <http://app.pl> --run=service_func
-- Best Regards, Nick Knutov http://knutov.com ICQ: 272873706 Voice: +7-904-84-23-130 _________________________________________________ Dancer-users mailing list Dancer-users@perldancer.org <mailto:Dancer-users@perldancer.org> http://www.backup-manager.org/__cgi-bin/listinfo/dancer-users <http://www.backup-manager.org/cgi-bin/listinfo/dancer-users>
-- Best Regards, Nick Knutov http://knutov.com ICQ: 272873706 Voice: +7-904-84-23-130
On Sun, 2011-07-03 at 10:25 +0600, Nick Knutov wrote:
Thanks! Look like exactly what I need.
btw, is there any way to run 'before' in such scripts?
Well, 'before' handlers are supposed to run before a request; given that you're looking at a script where there is no request, I think them not running is correct and expected.
I changed
before sub {...}
to
sub _init {...} before sub {_init()}; # in main app
app::_init(); # in Dancer ':script' app
but this is ugly.
It'll do the job, even if a little ugly. Personally, if it's code that should run on startup before any requests are processed, I'd just put it in the script as-is, rather than in a before handler - e.g. use Dancer qw(:script); # my initialisation code goes here # now declare routes -- David Precious ("bigpresh") http://www.preshweb.co.uk/ "Programming is like sex. One mistake and you have to support it for the rest of your life". (Michael Sinz)
participants (5)
-
David Precious -
Flavio Poletti -
Gurunandan Bhat -
Jury Gorky -
Nick Knutov