diff options
author | Roland Huß <roland@ro14nd.de> | 2022-09-06 11:36:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-06 11:36:06 +0200 |
commit | 7943f46f620b0cf4452d64d7d9ff3da7abe9cd65 (patch) | |
tree | 5091c57d675245cb153ea4513a5d35d7550d73d3 | |
parent | b9e31e4f84368af03047f04821e4762364172d4a (diff) | |
parent | 03a10ab00641c24ab4e25d7070b51be963acbb9a (diff) |
Merge pull request #9 from NicholasBHubbard/master
Add processname option for setting $0 to constant string
-rw-r--r-- | lib/Schedule/Cron.pm | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/Schedule/Cron.pm b/lib/Schedule/Cron.pm index 13f6ec6..70936c9 100644 --- a/lib/Schedule/Cron.pm +++ b/lib/Schedule/Cron.pm @@ -334,6 +334,11 @@ option you can set it to something different. You can e.g. use C<$0> to include the original process name. You can inhibit this with the C<nostatus> option, and prevent the argument display by setting C<loglevel> to zero or higher. +=item processname => <name> + +Set the process name (i.e. C<$0>) to a literal string. Using this setting +overrides C<processprefix> and C<nostatus>. + =item sleep => \&hook If specified, &hook will be called instead of sleep(), with the time to sleep @@ -879,6 +884,10 @@ sub run }; } + if (my $name = $cfg->{processname}) { + $0 = $name + } + my $mainloop = sub { MAIN: while (42) @@ -911,7 +920,11 @@ sub run { $sleep = $time - $now; } - $0 = $self->_get_process_prefix()." MainLoop - next: ".scalar(localtime($time)) unless $cfg->{nostatus}; + + unless ($cfg->{processname} || $cfg->{nostatus}) { + $0 = $self->_get_process_prefix()." MainLoop - next: ".scalar(localtime($time)); + } + if (!$time) { die "Internal: No time found, self: ",$self->{queue},"\n" unless $time; } @@ -1012,7 +1025,10 @@ sub run } open STDERR, '>&STDOUT' or die "Can't dup stdout: $!"; - $0 = $self->_get_process_prefix()." MainLoop" unless $cfg->{nostatus}; + unless ($cfg->{processname} || $cfg->{nostatus}) { + $0 = $self->_get_process_prefix()." MainLoop"; + } + &$mainloop(); } } @@ -1292,10 +1308,10 @@ sub _execute } - if ($log && $loglevel <= 0 || !$cfg->{nofork} && !$cfg->{nostatus}) { + if ($log && $loglevel <= 0 || !$cfg->{nofork} && !$cfg->{processname} && !$cfg->{nostatus}) { my $args_label = (@args && $loglevel <= -1) ? " with (".join(",",$self->_format_args(@args)).")" : ""; $0 = $self->_get_process_prefix()." Dispatched job $index$args_label" - unless $cfg->{nofork} || $cfg->{nostatus}; + unless $cfg->{nofork} || $cfg->{processname} || $cfg->{nostatus}; $log->(0,"Schedule::Cron - Starting job $index$args_label") if $log && $loglevel <= 0; } |