[dw-free] Fix import-schedule so it runs constantly
[commit: http://hg.dwscoalition.org/dw-free/rev/2bdb958ff09c]
http://bugs.dwscoalition.org/show_bug.cgi?id=1491
Add verbose mode to import-scheduler, also make it not exit every pass.
Patch by
fu.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=1491
Add verbose mode to import-scheduler, also make it not exit every pass.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- bin/worker/import-scheduler
- bin/worker/paidstatus
-------------------------------------------------------------------------------- diff -r 1cd34d18d821 -r 2bdb958ff09c bin/worker/import-scheduler --- a/bin/worker/import-scheduler Mon Oct 17 11:09:27 2011 -0500 +++ b/bin/worker/import-scheduler Mon Oct 17 20:47:27 2011 +0000 @@ -19,10 +19,20 @@ use lib "$ENV{LJHOME}/cgi-bin"; require 'ljlib.pl'; +use Time::HiRes qw/ gettimeofday tv_interval /; + +$| = 1; # Line buffered. +my $DEBUG = 0; sub _log { - open FILE, ">>$ENV{LJHOME}/logs/import-scheduler.log" or die; - print FILE "[$$] " . sprintf( shift() . "\n", @_ ); - close FILE; + my $txt = "[$$] " . sprintf( shift() . "\n", @_ ); + + if ( $DEBUG ) { + print $txt; + } else { + open FILE, ">>$ENV{LJHOME}/logs/import-scheduler.log" or die; + print FILE $txt; + close FILE; + } return undef; } @@ -143,6 +153,24 @@ } } -# okay, actually run the job -worker_helper(); -exit 0; +my $begin_time = [ gettimeofday() ]; +# run the job in a loop +while ( 1 ) { + $DEBUG = 1 if $ARGV[0] =~ /^--?v(?:erbose)?$/; + _log( 'Main loop beginning...' ); + + worker_helper(); + + # now we sleep to the next one minute boundary, and if we're taking more + # than one minute to run, we fire off an alert + my $sleep_time = 60 - tv_interval( $begin_time ); + if ( $sleep_time < 0 ) { + _log( 'Warning: main loop is taking longer than a minute.' ); + $sleep_time = 60; + } + _log( 'Sleeping for %0.2f seconds.', $sleep_time ); + select undef, undef, undef, $sleep_time; + + _log( 'Main loop ended.' ); + $begin_time = [ gettimeofday() ]; +} diff -r 1cd34d18d821 -r 2bdb958ff09c bin/worker/paidstatus --- a/bin/worker/paidstatus Mon Oct 17 11:09:27 2011 -0500 +++ b/bin/worker/paidstatus Mon Oct 17 20:47:27 2011 +0000 @@ -73,10 +73,10 @@ # do this in a sub so it can return on error main_loop(); - # now we sleep to the next five minute boundary, and if we're taking more - # than five minutes to run, we fire off an alert - my $sleep_time = 60 - ( tv_interval( $begin_time ) % 60 ); - if ( $sleep_time < 0 ) { + # now we sleep to the next one minute boundary, and if we're taking more + # than one minute to run, we fire off an alert + my $sleep_time = 60 - tv_interval( $begin_time ); + if ( $sleep_time <= 0 ) { $alert->( 'Warning: main loop is taking longer than a minute.' ); $sleep_time = 60; } --------------------------------------------------------------------------------