Skip to content

Commit

Permalink
crawler lane in dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Hai Zheng committed Dec 11, 2023
1 parent 9c95db2 commit 12a5504
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/crawler.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ private function _prepare_running()
*/
private function _take_over_lane()
{
file::save($this->json_path() . '.pid', LITESPEED_LANE_HASH);
file::save($this->json_local_path() . '.pid', LITESPEED_LANE_HASH);
}

/**
Expand All @@ -596,7 +596,7 @@ private function _take_over_lane()
*/
private function _touch_lane()
{
touch($this->json_path() . '.pid');
touch($this->json_local_path() . '.pid');
}

/**
Expand All @@ -605,7 +605,7 @@ private function _touch_lane()
*/
private function _release_lane()
{
unlink($this->json_path() . '.pid');
unlink($this->json_local_path() . '.pid');
}

/**
Expand All @@ -615,8 +615,15 @@ private function _release_lane()
private function _check_valid_lane()
{
// Check lane hash
$pid = file::read($this->json_path() . '.pid');
$lane_file = $this->json_local_path() . '.pid';
$pid = file::read($lane_file);
if ($pid && LITESPEED_LANE_HASH != $pid) {
// If lane file is older than 1h, ignore
if (time() - filemtime($lane_file) > 3600) {
self::debug("Lane file is older than 1h, releasing lane");
$this->_release_lane();
return true;
}
return false;
}
return true;
Expand Down Expand Up @@ -1159,6 +1166,21 @@ private function _recursive_build_crawler($crawler_factors, $group = array(), $i
return $final_list;
}

/**
* Return crawler meta file local path
*
* @since 6.1
* @access public
*/
public function json_local_path()
{
if (!file_exists(LITESPEED_STATIC_DIR . '/crawler/' . $this->_sitemeta)) {
return false;
}

return LITESPEED_STATIC_DIR . '/crawler/' . $this->_sitemeta;
}

/**
* Return crawler meta file
*
Expand Down

0 comments on commit 12a5504

Please sign in to comment.