[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] sleep vs. other method



I'm working on a script to report on the sucess or failure of automated
installs with netOctopus.  Unlike the previous script I posted, which
essentially abstracts out information about past installs, this script will
initiate and monitor the progress of an install.

I'm having some trouble getting it to function properly, due to timing
issues.  Here's the section that I'm having trouble with:
####
while ($log{'currentPosition'} != $log{'lastPosition'})	{
	@lines = $nO->get($nO->obj(lines =>
					range($log{'lastPosition'},
					      $log{'currentPosition'}),
					property => 'log_window'));
	$log{'lastPosition'} = $log{'currentPosition'};

	foreach my $line (@lines)	{
	  my ($date,$time,$zone,$user,$comment);
	  ($date,$time,$zone,$user,$comment) = $line =~ m!(.*)\s
	  						(.*M)\s+
	  						«\[(.*)]\s
	  						(.*)»:(.*)!x;
	  print "Current user & comment is $user:$comment\n" if $debug;
	  if (exists $report{$user})	{
	    if ($comment =~ /.*Starting.*script '$scriptName'.../){
	    	$report{$user}{'status'} = 'started';
	    };
	    if ($comment =~ /.*script '$scriptName' finished successfully.*/) {
	 	$report{$user}{'status'} = 'succeeded';
	    };
	    if ($comment =~ /.*'$scriptName' failed \((.*)\)/)	{
		$report{$user}{'reason'} = $1;
		$report{$user}{'status'} = 'failure';
	    };
	  };
	};
	sleep(45);
	$log{'currentPosition'} = $nO->count($nO->prop('log_window'),
'each' => 'line');
};
###

The difficulty I'm having is that this loop terminates before I'd like it
too.  What's happening is that lines are not being added to the log fast
enough.

I could very easily increase the sleep time.  I am also looking into other
ways of telling if the installs I'm looking at are finished - because
waiting until the log doesn't change any more is not a great way to do it,
as it might potentially never stop changing.  That's not very likely, and
watching the log is the most straightforward method, I think.

I'm looking for some other ideas, though. I realize that most of you don't
have netOctopus lying around, but I'm asking about a more general problem.

-Jeff Lowrey



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org