Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Modified Janitor to only run certain tasks rarely (ie, UpdateNodeNetw…
Browse files Browse the repository at this point in the history
…ork)
  • Loading branch information
michaelchisari authored and The Appleseed Project committed Jan 26, 2011
1 parent cfe092d commit 684d937
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
10 changes: 10 additions & 0 deletions _release/update-0.7.10.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

alter table `#__Janitor` add `Task` char(64);

alter table `#__Janitor` add primary key ( `Task` );

update `#__Janitor` set Task = 'Janitorial';

insert into `#__Janitor` ( `Updated`, `Task` ) values ( NOW(), 'UpdateNodeNetwork' );

insert into `#__Janitor` ( `Updated`, `Task` ) values ( NOW(), 'ProcessNewsfeed' );
49 changes: 36 additions & 13 deletions components/janitor/controllers/janitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,48 @@ function Display ( $pView = null, $pData = array ( ) ) {

$Model->Retrieve();

$Model->Fetch();
while ( $Model->Fetch() ) {
$Task = $Model->Get ( 'Task' );
$Tasks[$Task] = strtotime ( $Model->Get ( 'Updated' ) );
}

$lastUpdated = strtotime ( $Model->Get ( 'Updated' ) );
// Run the janitor every minute.
// TODO: Make this configurable.
if ( !$this->_IsPast ( $Tasks['Janitorial'], 1 ) ) return ( true );
$Model->Set ( 'Updated', NOW() );
$Model->Save ( array ( 'Task' => 'Janitorial' ) );

// Process the newsfeed every FIVE minutes.
// TODO: Make this configurable.
if ( $this->_IsPast ( $Tasks['ProcessNewsfeed'], 5 ) ) {
$this->Talk ( 'Newsfeed', 'ProcessQueue' );
$Model->Set ( 'Updated', NOW() );
$Model->Save ( array ( 'Task' => 'ProcessNewsfeed' ) );
}

// Update the node network every 24 hours.
// TODO: Make this configurable.
if ( $this->_IsPast ( $Tasks['UpdateNodeNetwork'], 1440 ) ) {
$this->GetSys ( 'Event' )->Trigger ( 'Update', 'Node', 'Network' );
$Model->Set ( 'Updated', NOW() );
$Model->Save ( array ( 'Task' => 'UpdateNodeNetwork' ) );
}

return ( true );
}

private function _IsPast ( $pTime, $pDistance ) {

if ( !$pTime ) return ( false );

$now = strtotime ( NOW() );

$diff = $now - $lastUpdated;
$diff = $now - $pTime;
$diffMinutes = $diff / 60;

if ( $diffMinutes < 1 ) return ( true );
if ( $diffMinutes < $pDistance ) return ( false );

$this->Talk ( 'Newsfeed', 'ProcessQueue' );

$this->GetSys ( 'Event' )->Trigger ( 'Update', 'Node', 'Network' );

$Model->Query(' DELETE FROM #__Janitor' );
$Model->Set ( 'Updated', NOW() );
$Model->Save();

return ( true );
return ( true );
}

}
2 changes: 1 addition & 1 deletion hooks/janitor/janitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function EndFooterDisplay ( $pData = null ) {

$Model = new cModel('Janitor');

$Model->Retrieve();
$Model->Retrieve( array ( 'Task' => 'Janitorial' ) );

$Model->Fetch();

Expand Down

0 comments on commit 684d937

Please sign in to comment.