The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
Build.PL 11
Changes 012
META.json 46
META.yml 2223
README.md 310
cpanfile 01
eg/cron.pl 01
lib/Proclet/Declare.pm 524
lib/Proclet.pm 531
t/02_declare.t 01
t/04_disable_log.t 11
t/30proclet/01_basic.t 01
t/30proclet/02_process.t 01
t/DeclareProclet.pl 09
14 files changed (This is a version diff) 41122
@@ -34,7 +34,7 @@ my %args = (
     test_files           => ((-d '.git' || $ENV{RELEASE_TESTING}) && -d 'xt') ? 't/ xt/' : 't/',
     recursive_test_files => 1,
 
-    
+
 );
 if (-d 'share') {
     $args{share_dir} = 'share';
@@ -1,5 +1,17 @@
 Revision history for Perl extension Proclet
 
+0.35 2014-07-24T05:31:01Z
+
+       - add opt to disable exec message
+
+0.34 2014-04-10T15:33:21Z
+
+       - support cron like job in Declare (EXPERIMENTAL)
+
+0.33 2014-03-12T15:20:48Z
+
+       - add start and exec message
+
 0.32 2013-12-27T04:39:01Z
 
         - support cron like job (EXPERIMENTAL)
@@ -4,7 +4,7 @@
       "Masahiro Nagano <kazeburo {at} gmail.com>"
    ],
    "dynamic_config" : 0,
-   "generated_by" : "Minilla/v0.11.0",
+   "generated_by" : "Minilla/v1.1.0",
    "license" : [
       "perl_5"
    ],
@@ -36,7 +36,8 @@
       "develop" : {
          "requires" : {
             "Test::CPAN::Meta" : "0",
-            "Test::MinimumVersion" : "0.10108",
+            "Test::MinimumVersion::Fast" : "0.04",
+            "Test::PAUSE::Permissions" : "0.04",
             "Test::Pod" : "1.41",
             "Test::Spellunker" : "v0.2.7"
          }
@@ -49,6 +50,7 @@
             "Log::Minimal" : "0.14",
             "Mouse" : "0",
             "Parallel::Prefork" : "0.13",
+            "String::ShellQuote" : "0",
             "Term::ANSIColor" : "0",
             "Time::Crontab" : "0.01",
             "YAML::XS" : "0.38",
@@ -68,7 +70,7 @@
    "provides" : {
       "Proclet" : {
          "file" : "lib/Proclet.pm",
-         "version" : "0.32"
+         "version" : "0.35"
       },
       "Proclet::Declare" : {
          "file" : "lib/Proclet/Declare.pm"
@@ -85,7 +87,7 @@
          "web" : "https://github.com/kazeburo/Proclet"
       }
    },
-   "version" : "0.32",
+   "version" : "0.35",
    "x_contributors" : [
       "soh335 <sugarbabe335@gmail.com>",
       "Masahiro Nagano <kazeburo@gmail.com>"
@@ -3,20 +3,20 @@ abstract: 'minimalistic Supervisor'
 author:
   - 'Masahiro Nagano <kazeburo {at} gmail.com>'
 build_requires:
-  List::MoreUtils: 0
-  Parallel::Scoreboard: 0
-  Test::More: 0
-  Test::Requires: 0
+  List::MoreUtils: '0'
+  Parallel::Scoreboard: '0'
+  Test::More: '0'
+  Test::Requires: '0'
 configure_requires:
-  CPAN::Meta: 0
-  CPAN::Meta::Prereqs: 0
-  Module::Build: 0.38
+  CPAN::Meta: '0'
+  CPAN::Meta::Prereqs: '0'
+  Module::Build: '0.38'
 dynamic_config: 0
-generated_by: 'Minilla/v0.11.0, CPAN::Meta::Converter version 2.132830'
+generated_by: 'Minilla/v1.1.0, CPAN::Meta::Converter version 2.141170'
 license: perl
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.4.html
-  version: 1.4
+  version: '1.4'
 name: Proclet
 no_index:
   directory:
@@ -31,26 +31,27 @@ no_index:
 provides:
   Proclet:
     file: lib/Proclet.pm
-    version: 0.32
+    version: '0.35'
   Proclet::Declare:
     file: lib/Proclet/Declare.pm
 requires:
-  Data::Validator: 0
-  File::Which: 1.09
-  Getopt::Compact::WithCmd: 0.20
-  Log::Minimal: 0.14
-  Mouse: 0
-  Parallel::Prefork: 0.13
-  Term::ANSIColor: 0
-  Time::Crontab: 0.01
-  YAML::XS: 0.38
-  parent: 0
-  perl: 5.008001
+  Data::Validator: '0'
+  File::Which: '1.09'
+  Getopt::Compact::WithCmd: '0.20'
+  Log::Minimal: '0.14'
+  Mouse: '0'
+  Parallel::Prefork: '0.13'
+  String::ShellQuote: '0'
+  Term::ANSIColor: '0'
+  Time::Crontab: '0.01'
+  YAML::XS: '0.38'
+  parent: '0'
+  perl: '5.008001'
 resources:
   bugtracker: https://github.com/kazeburo/Proclet/issues
   homepage: https://github.com/kazeburo/Proclet
   repository: git://github.com/kazeburo/Proclet.git
-version: 0.32
+version: '0.35'
 x_contributors:
   - 'soh335 <sugarbabe335@gmail.com>'
   - 'Masahiro Nagano <kazeburo@gmail.com>'
@@ -48,7 +48,6 @@ Proclet - minimalistic Supervisor
     );
 
 
-
     $proclet->run;
 
 # DESCRIPTION
@@ -102,6 +101,14 @@ Logs from services are Displayed with timestamp and tag.
         enable worker for format logs. (default: 1)
         If disabled this option, cannot use logger opt too.
 
+    - exec\_notice: Bool
+
+        enable start and exec notice message like
+
+            16:38:12 worker.1 | Start callback: worker
+
+        (default: 1)
+
 - service
 
     Add services to Proclet.
@@ -164,8 +171,8 @@ Masahiro Nagano <kazeburo {at} gmail.com>
 
 # SEE ALSO
 
-[Proc::Launcher::Manager](http://search.cpan.org/perldoc?Proc::Launcher::Manager), related module
-[Parallel::Prefork](http://search.cpan.org/perldoc?Parallel::Prefork), Proclet used internally
+[Proc::Launcher::Manager](https://metacpan.org/pod/Proc::Launcher::Manager), related module
+[Parallel::Prefork](https://metacpan.org/pod/Parallel::Prefork), Proclet used internally
 
 # LICENSE
 
@@ -9,6 +9,7 @@ requires 'Term::ANSIColor';
 requires 'YAML::XS', '0.38';
 requires 'parent';
 requires 'Time::Crontab', '0.01';
+requires 'String::ShellQuote';
 
 on test => sub {
     requires 'List::MoreUtils';
@@ -8,6 +8,7 @@ use Log::Minimal;
 
 my $proclet = Proclet->new;
 $proclet->service(
+    tag => 'cron_sample',
     code => sub {
         warnf $0;
         sleep 5;
@@ -5,7 +5,7 @@ use warnings;
 use Proclet;
 use parent qw/Exporter/;
 
-our @EXPORT = qw/color env service worker run/;
+our @EXPORT = qw/color env service scheduled worker run/;
 
 our %REGISTRY;
 
@@ -36,7 +36,17 @@ sub service {
     my $code = ( ref($service[0]) && ref($service[0]) eq 'CODE' )
         ? $service[0] 
         : \@service;
-    push @{_proclet->{service}},[$tag,$code];
+    push @{_proclet->{service}},{ tag => $tag, code => $code };
+}
+
+sub scheduled {
+    my $tag = shift;
+    my $cron = shift;
+    my @service = @_;
+    my $code = ( ref($service[0]) && ref($service[0]) eq 'CODE' )
+        ? $service[0] 
+        : \@service;
+    push @{_proclet->{service}},{ tag => $tag, code => $code, every => $cron };
 }
 
 sub worker {
@@ -52,10 +62,9 @@ sub run() { ## no critic
     }
     my $proclet = Proclet->new(color => _proclet->{color});
     foreach my $service ( @{_proclet->{service}} ) {
-        my ($tag, $code) = @$service;
+        my $tag = $service->{tag};
         $proclet->service(
-            tag => $tag,
-            code => $code,
+            %$service,
             worker => ( exists _proclet->{worker}->{$tag} ) ? _proclet->{worker}->{$tag} : 1
         );
     }
@@ -83,6 +92,7 @@ Proclet::Declare - Declare interface to Proclet
   service('web', 'plackup -p 5963 app.psgi');
   service('memcached', '/usr/local/bin/memcached', '-p', '11211');
   service('worker', './bin/worker');
+  scheduled('tag', '0 12 * * *', sub { MyDailyWork->run });
 
   worker(
     'worker' => 5
@@ -126,6 +136,15 @@ Sets the service
   # exec command
   service('tag', '/usr/local/bin/memcached','-vv');
 
+=item scheduled
+
+scheduled job like cron
+
+  # coderef
+  scheduled('tag', '0 12 * * *', sub { MyDailyWork->run });
+  # exec command
+  scheduled('tag', '0 12 * * *', 'my_daily_job','-execute');
+
 =item worker
 
 Number of children to fork
@@ -12,6 +12,7 @@ use IO::Select;
 use Term::ANSIColor;
 use File::Which;
 use Time::Crontab;
+use String::ShellQuote;
 
 subtype 'ServiceProcs'
     => as 'Int'
@@ -28,10 +29,13 @@ coerce 'Proclet::Service'
     => from 'ArrayRef' => via {
         my $command = $_;
         +{generator => sub {
+            my $notice = shift;
             my @command = @{$command};
+            my @o_command = @command;
             my $bash = which("bash");
             if ( @command == 1 && $bash ) { unshift @command, $bash, "-c" }
             sub {
+                infof "Exec command: ". shell_quote(@o_command)."\n" if $notice;
                 exec(@command);
                 die $!
             }
@@ -40,20 +44,28 @@ coerce 'Proclet::Service'
     => from 'Str' => via {
         my $o_command = $_;
         +{generator => sub {
-            my $port = shift;
+            my ($notice, $port, $tag) = @_;
             my $command = $o_command; #copy
             $command =~ s/\$PORT/$port/g if $port;
             my @command = ($command);
+            my @o_command = @command;
             if ( my $bash = which("bash") ) { unshift @command, $bash, "-c" }
             sub {
-                exec @command;
+                infof "Exec command: ". shell_quote(@o_command)."\n" if $notice;
+                exec(@command);
                 die $!
             }
         }}
     }
     => from 'CodeRef' => via {
         my $command = $_;
-        +{generator => sub { $command }};
+        +{generator => sub {
+              my ($notice, $port, $tag) = @_;
+              sub {
+                  infof "Start callback: " . $tag  . "\n" if $notice;
+                  $command->($port);
+              }
+          }};
     };
 
 
@@ -73,7 +85,7 @@ coerce 'Proclet::Scheduler'
 
 no Mouse::Util::TypeConstraints;
 
-our $VERSION = '0.32';
+our $VERSION = '0.35';
 
 has '_services' => (
     is => 'ro',
@@ -111,6 +123,12 @@ has 'enable_log_worker' => (
     default => 1,
 );
 
+has 'exec_notice' => (
+    is => 'ro',
+    isa => 'Int',
+    default => 1,
+);
+
 # for Procfile port assignment
 has '_base_port' => (
     is => 'ro',
@@ -165,7 +183,7 @@ sub run {
             $services{$sid} = { %$service };
             my $port =  $services{$sid}{start_port} + $i - 1;
             my $code_generator = $services{$sid}{code}{generator};
-            my $code = $code_generator->($port);
+            my $code = $code_generator->($self->exec_notice, $port, $service->{tag});
             if ( $services{$sid}{cron} ) {
                 $code = $self->cron_worker($code,$services{$sid}{cron});
             }
@@ -485,6 +503,14 @@ Sets a callback to print stdout/stderr. uses warn by default.
 enable worker for format logs. (default: 1)
 If disabled this option, cannot use logger opt too.
 
+=item exec_notice: Bool
+
+enable start and exec notice message like
+
+  16:38:12 worker.1 | Start callback: worker
+
+(default: 1)
+
 =back
 
 =item service
@@ -9,6 +9,7 @@ $ENV{PROCLET_TESTFILE} = $logfile;
 die $! if ! defined $pid;
 
 if ( $pid == 0 ) {
+    close(STDERR);
     exec $^X, 't/DeclareProclet.pl';
     die $!;
 }
@@ -29,7 +29,7 @@ my $stderr  = Capture::Tiny::capture_stderr {
 
 my $ok = 0;
 for my $l ( split /\n/, $stderr ) {
-    like $l, qr/^proclet disable log at/;
+    like $l, qr/^(\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d \[INFO\] Start callback|proclet disable log at)/;
     $ok++ if $l =~ m!^proclet disable log at!;
 }
 ok($ok);
@@ -11,6 +11,7 @@ die $! if ! defined $pid;
 
 if ( $pid == 0 ) {
     chdir 't/30proclet/procfile';
+    close(STDERR);
     exec $^X, '-I../../../lib','../../../bin/proclet', 'start';
     exit;
 }
@@ -11,6 +11,7 @@ die $! if ! defined $pid;
 
 if ( $pid == 0 ) {
     chdir 't/30proclet/procfile';
+    close(STDERR);
     exec $^X, '-I../../../lib','../../../bin/proclet', 'start','-p','3000','w2';
     exit;
 }
@@ -16,6 +16,15 @@ service(
     'for(1..100){ open(my $fh, ">>:unix", $ENV{PROCLET_TESTFILE}) or die $!; print $fh "w2 $$\n"; close $fh; sleep 1}'
 );
 
+scheduled(
+    'c1',
+    '* * * * *',
+    $^X,
+    '-e',
+    'sleep 1;'
+);
+
+
 worker(
     'w2' => 2
 );