Ignore:
Timestamp:
03/30/16 13:09:45 (8 years ago)
Author:
nanardon
Message:

Make la-sync-manager simplier, better granularity about when running modules

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Task.pm

    r1737 r1740  
    9393sub runDelay { 0; } 
    9494 
     95=head2 waitDelay 
     96 
     97Return the number of second to wait before next run even there is a change in database. 
     98 
     99Return 0 but can be override by Task module. 
     100 
     101=cut 
     102 
     103sub waitDelay { 0; } 
     104 
     105=head2 needToBeRun 
     106 
     107Return TRUE is the module has to be run or not. 
     108 
     109=cut 
     110 
     111sub needToBeRun { 
     112    my ($self, $Sync, $module) = @_; 
     113 
     114    my ($lastrev, $lastRunTime) = $Sync->get_last_rev($module); 
     115 
     116    my $currentrev = $Sync->dbrev; 
     117    my $currentTime = time; 
     118     
     119    if ($currentTime < $lastRunTime + $self->waitDelay) { 
     120        la_log LA_DEBUG, "Too early to run this module now"; 
     121        return 0; 
     122    } 
     123 
     124    if ($self->needupd($lastrev, $currentrev, $Sync)) { 
     125        return 1; 
     126    } else { 
     127        la_log LA_DEBUG, "No change on main base, cheking delay"; 
     128    } 
     129 
     130 
     131    if (my $delay = $self->runDelay) { 
     132        if ($currentTime >= $lastRunTime + $self->runDelay) { 
     133            return 1; 
     134        } else { 
     135            la_log LA_DEBUG, "Too short delay to run self, waiting"; 
     136        } 
     137    } 
     138 
     139    return 0; 
     140} 
     141 
    95142=head2 run 
    96143 
Note: See TracChangeset for help on using the changeset viewer.