Permalink
Browse files

Fix uncaught API budget exception in twitter crawler

- Catch APICallLimitExceededException for TwitterCrawler->fetchInstanceUserGroups()
Closes #1061
  • Loading branch information...
1 parent 74ed49a commit ce935d6854124fdb51035cdfd75e2b4a1e7a7dc9 @mwilkie mwilkie committed with ginatrapani Oct 23, 2011
@@ -824,7 +824,11 @@ public function fetchInstanceUserGroups() {
}
$args['cursor'] = strval($next_cursor);
- list($cURL_status, $twitter_data) = $this->api->apiRequest($groups, $args);
+ try {
+ list($cURL_status, $twitter_data) = $this->api->apiRequest($groups, $args);
+ } catch (APICallLimitExceededException $e) {
+ break;
+ }
if ($cURL_status > 200) {
$continue_fetching = false;
@@ -496,6 +496,23 @@ public function testFetchInstanceUserGroups() {
$this->assertEqual(count($history['history']), 1);
}
+ public function testFetchInstanceUserGroupsBudget() {
+ self::setUpInstanceUserAnilDash();
+ // set up crawl limit budget
+ $crawl_limit = array('fetchInstanceUserGroups' => array('count' => 2, 'remaining' => 0) );
+ $this->api->setCallerLimits($crawl_limit);
+ $twitter_crawler = new TwitterCrawler($this->instance, $this->api);
+
+ $twitter_crawler->fetchInstanceUserGroups();
+ $group_dao = DAOFactory::getDAO('GroupDAO');
+ $this->assertFalse($group_dao->isGroupInStorage($group = '1234566', 'twitter'), 'group does not exist');
+
+ $group_member_dao = DAOFactory::getDAO('GroupMemberDAO');
+ $this->assertFalse($group_member_dao->isGroupMemberInStorage($user = '36823', $group = '1234566', 'twitter'),
+ 'group member does not exists');
+
+ }
+
public function testUpdateStaleGroupMemberships() {
self::setUpInstanceUserAnilDash();
$twitter_crawler = new TwitterCrawler($this->instance, $this->api);

0 comments on commit ce935d6

Please sign in to comment.