Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #158: Crawler run notifier alerts you if the crawler hasn't upd…
…ated an instance in more than 3 hours
- Loading branch information
1 parent
715ab81
commit ef24456
Showing
8 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
require_once dirname(__FILE__).'/config.tests.inc.php'; | ||
require_once $SOURCE_ROOT_PATH.'extlib/simpletest/autorun.php'; | ||
ini_set("include_path", ini_get("include_path").PATH_SEPARATOR.$INCLUDE_PATH); | ||
|
||
require_once $SOURCE_ROOT_PATH.'tests/classes/class.ThinkUpUnitTestCase.php'; | ||
require_once $SOURCE_ROOT_PATH.'webapp/controller/class.ThinkUpController.php'; | ||
require_once $SOURCE_ROOT_PATH.'tests/fixtures/class.FixtureBuilder.php'; | ||
require_once $SOURCE_ROOT_PATH.'tests/fixtures/class.FixtureBuilderException.php'; | ||
require_once $SOURCE_ROOT_PATH.'webapp/controller/class.CheckCrawlerController.php'; | ||
require_once $SOURCE_ROOT_PATH.'extlib/Smarty-2.6.26/libs/Smarty.class.php'; | ||
require_once $SOURCE_ROOT_PATH.'webapp/model/class.SmartyThinkUp.php'; | ||
require_once $SOURCE_ROOT_PATH.'webapp/model/class.Instance.php'; | ||
require_once $SOURCE_ROOT_PATH.'webapp/model/class.DAOFactory.php'; | ||
require_once $SOURCE_ROOT_PATH.'webapp/model/class.Profiler.php'; | ||
require_once $SOURCE_ROOT_PATH.'webapp/model/class.Session.php'; | ||
|
||
/** | ||
* Test of CheckCrawlerController | ||
* | ||
* @author Gina Trapani <ginatrapani[at]gmail[dot]com> | ||
* | ||
*/ | ||
class TestOfCheckCrawlerController extends ThinkUpUnitTestCase { | ||
|
||
public function __construct() { | ||
$this->UnitTestCase('CheckCrawlerController class test'); | ||
} | ||
|
||
public function setUp(){ | ||
parent::setUp(); | ||
} | ||
|
||
public function tearDown(){ | ||
parent::tearDown(); | ||
} | ||
|
||
public function testConstructor() { | ||
$controller = new CheckCrawlerController(true); | ||
$this->assertTrue(isset($controller)); | ||
} | ||
|
||
public function testNoInstances() { | ||
$controller = new CheckCrawlerController(true); | ||
$results = $controller->go(); | ||
$this->assertEqual('', $results); | ||
} | ||
|
||
public function testInstanceLessThan3Hours() { | ||
$instance_builder = FixtureBuilder::build('instances', array('crawler_last_run'=>'-1h')); | ||
$controller = new CheckCrawlerController(true); | ||
$results = $controller->go(); | ||
$this->assertEqual('', $results); | ||
} | ||
|
||
public function testInstanceMoreThan3Hours() { | ||
$instance_builder = FixtureBuilder::build('instances', array('crawler_last_run'=>'-4h')); | ||
$controller = new CheckCrawlerController(true); | ||
$results = $controller->go(); | ||
$this->assertEqual("Crawler hasn't run in 4 hours", $results); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
/** | ||
* CheckCrawler Controller | ||
* Outputs a message if crawler hasn't run in a certain number of hours | ||
* @author Gina Trapani <ginatrapani[at]gmail[dot]com> | ||
* | ||
*/ | ||
class CheckCrawlerController extends ThinkUpController { | ||
var $THRESHOLD = 3; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param boolean $session_started | ||
*/ | ||
public function __construct($session_started=false) { | ||
parent::__construct($session_started); | ||
$this->setViewTemplate('crawler.checkcrawler.tpl'); | ||
} | ||
|
||
public function control() { | ||
$instance_dao = DAOFactory::getDAO('InstanceDAO'); | ||
$hours_since_last_crawl = $instance_dao->getHoursSinceLastCrawlerRun(); | ||
if (isset($hours_since_last_crawl) && $hours_since_last_crawl > $this->THRESHOLD) { | ||
$this->addToView('message', "Crawler hasn't run in ".round($hours_since_last_crawl)." hours"); | ||
} | ||
return $this->generateView(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
require_once 'init.php'; | ||
require_once 'controller/class.CheckCrawlerController.php'; | ||
|
||
$controller = new CheckCrawlerController(); | ||
echo $controller->go(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{$message} |