Process tree updated to show daemon worker status/activity

Squashed commit of the following:

commit a785b88b43
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Aug 6 21:32:11 2014 +0100

    complete daemon pstree updates

commit f77bf5361f
Merge: f519410 fcb8195
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Aug 6 20:45:22 2014 +0100

    Merge branch 'master' into og-proctitle

commit f51941076f
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Aug 5 22:14:58 2014 +0100

    set proctitle on daemon
This commit is contained in:
Oliver Gorwits
2014-08-06 21:33:41 +01:00
parent fcb8195e58
commit 5d23338cbd
8 changed files with 80 additions and 8 deletions

View File

@@ -56,6 +56,23 @@ __PACKAGE__->set_primary_key("job");
# You can replace this text with custom code or comments, and it will be preserved on regeneration
=head1 METHODS
=head2 summary
An attempt to make a meaningful statement about the job.
=cut
sub summary {
my $job = shift;
return join ' ',
$job->action,
($job->device || ''),
($job->port || ''),
($job->subaction ? (q{'}. $job->subaction .q{'}) : '');
}
=head1 ADDITIONAL COLUMNS
=head2 entererd_stamp

View File

@@ -44,8 +44,44 @@ __PACKAGE__->add_columns(
__PACKAGE__->set_primary_key("job");
=head1 METHODS
=head2 summary
An attempt to make a meaningful statement about the job.
=cut
sub summary {
my $job = shift;
return join ' ',
$job->action,
($job->device || ''),
($job->port || ''),
($job->subaction ? (q{'}. $job->subaction .q{'}) : '');
}
=head1 ADDITIONAL COLUMNS
=head2 extra
Alias for the C<subaction> column.
=cut
sub extra { (shift)->subaction }
=head2 entererd_stamp
Formatted version of the C<entered> field, accurate to the minute.
The format is somewhat like ISO 8601 or RFC3339 but without the middle C<T>
between the date stamp and time stamp. That is:
2012-02-06 12:49
=cut
sub entered_stamp {
(my $stamp = (shift)->entered) =~ s/\.\d+$//;
return $stamp;

View File

@@ -16,6 +16,7 @@ sub worker_body {
my $type = $self->worker_type;
while (1) {
$0 = sprintf 'netdisco-daemon: worker #%s %s: idle', $wid, lc($type);
my $jobs = jq_take($self->wid, $type);
foreach my $job (@$jobs) {
@@ -23,6 +24,8 @@ sub worker_body {
try {
$job->started(scalar localtime);
$0 = sprintf 'netdisco-daemon: worker #%s %s: working on #%s: %s',
$wid, lc($type), $job->id, $job->summary;
info sprintf "$tag (%s): starting %s job(%s) at %s",
$wid, $target, $job->id, $job->started;
my ($status, $log) = $self->$target($job);
@@ -42,9 +45,12 @@ sub worker_body {
sub close_job {
my ($self, $job) = @_;
my $tag = $self->worker_tag;
my $now = scalar localtime;
my $tag = $self->worker_tag;
my $type = $self->worker_type;
my $now = scalar localtime;
$0 = sprintf 'netdisco-daemon: worker #%s %s: wrapping up %s #%s: %s',
$self->wid, lc($type), $job->action, $job->id, $job->status;
info sprintf "$tag (%s): wrapping up %s job(%s) - status %s at %s",
$self->wid, $job->action, $job->id, $job->status, $now;

View File

@@ -11,18 +11,19 @@ use App::Netdisco::JobQueue qw/jq_locked jq_getsome jq_lock/;
sub worker_begin {
my $self = shift;
my $wid = $self->wid;
debug "entering Manager ($wid) worker_begin()";
if (setting('workers')->{'no_manager'}) {
return debug "mgr ($wid): no need for manager... skip begin";
}
return debug "mgr ($wid): no need for manager... skip begin"
if setting('workers')->{'no_manager'};
debug "entering Manager ($wid) worker_begin()";
# requeue jobs locally
debug "mgr ($wid): searching for jobs booked to this processing node";
my @jobs = jq_locked;
if (scalar @jobs) {
info sprintf "mgr (%s): found %s jobs booked to this processing node", $wid, scalar @jobs;
info sprintf "mgr (%s): found %s jobs booked to this processing node",
$wid, scalar @jobs;
$self->do('add_jobs', @jobs);
}
}
@@ -39,6 +40,7 @@ sub worker_body {
while (1) {
debug "mgr ($wid): getting potential jobs for $num_slots workers";
$0 = sprintf 'netdisco-daemon: worker #%s manager: gathering', $wid;
# get some pending jobs
# TODO also check for stale jobs in Netdisco DB
@@ -47,6 +49,7 @@ sub worker_body {
# check for available local capacity
my $job_type = setting('job_types')->{$job->action};
next unless $job_type and $self->do('capacity_for', $job_type);
debug sprintf "mgr (%s): processing node has capacity for job %s (%s)",
$wid, $job->id, $job->action;
@@ -60,6 +63,7 @@ sub worker_body {
}
debug "mgr ($wid): sleeping now...";
$0 = sprintf 'netdisco-daemon: worker #%s manager: idle', $wid;
sleep( setting('workers')->{sleep_time} || 2 );
}
}

View File

@@ -35,8 +35,12 @@ sub worker_body {
while (1) {
# sleep until some point in the next minute
my $naptime = 60 - (time % 60) + int(rand(45));
$0 = sprintf 'netdisco-daemon: worker #%s scheduler: idle', $wid;
debug "sched ($wid): sleeping for $naptime seconds";
sleep $naptime;
$0 = sprintf 'netdisco-daemon: worker #%s scheduler: queueing', $wid;
# NB next_time() returns the next *after* win_start
my $win_start = time - (time % 60) - 1;