Merge pull request #2533 from coreos-inc/fix-rac-bug
Fix NPE bug in RAC worker
This commit is contained in:
commit
a0c82d03a0
3 changed files with 9 additions and 5 deletions
|
@ -41,7 +41,7 @@ def find_uncounted_repository():
|
||||||
.order_by(db_random_func()).get())
|
.order_by(db_random_func()).get())
|
||||||
return to_count
|
return to_count
|
||||||
except Repository.DoesNotExist:
|
except Repository.DoesNotExist:
|
||||||
return 0
|
return None
|
||||||
|
|
||||||
|
|
||||||
def count_repository_actions(to_count):
|
def count_repository_actions(to_count):
|
||||||
|
|
|
@ -19,21 +19,22 @@ class RepositoryActionCountWorker(Worker):
|
||||||
to_count = model.repositoryactioncount.find_uncounted_repository()
|
to_count = model.repositoryactioncount.find_uncounted_repository()
|
||||||
if to_count is None:
|
if to_count is None:
|
||||||
logger.debug('No further repositories to count')
|
logger.debug('No further repositories to count')
|
||||||
return
|
return False
|
||||||
|
|
||||||
logger.debug('Found repository #%s to count', to_count.id)
|
logger.debug('Found repository #%s to count', to_count.id)
|
||||||
was_counted = model.repositoryactioncount.count_repository_actions(to_count)
|
was_counted = model.repositoryactioncount.count_repository_actions(to_count)
|
||||||
if not was_counted:
|
if not was_counted:
|
||||||
logger.debug('Repository #%s was counted by another worker', to_count.id)
|
logger.debug('Repository #%s was counted by another worker', to_count.id)
|
||||||
return
|
return False
|
||||||
|
|
||||||
logger.debug('Updating search score for repository #%s', to_count.id)
|
logger.debug('Updating search score for repository #%s', to_count.id)
|
||||||
was_updated = model.repositoryactioncount.update_repository_score(to_count)
|
was_updated = model.repositoryactioncount.update_repository_score(to_count)
|
||||||
if not was_updated:
|
if not was_updated:
|
||||||
logger.debug('Repository #%s had its search score updated by another worker', to_count.id)
|
logger.debug('Repository #%s had its search score updated by another worker', to_count.id)
|
||||||
return
|
return False
|
||||||
|
|
||||||
logger.debug('Repository #%s search score updated', to_count.id)
|
logger.debug('Repository #%s search score updated', to_count.id)
|
||||||
|
return True
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
worker = RepositoryActionCountWorker()
|
worker = RepositoryActionCountWorker()
|
||||||
|
|
|
@ -7,4 +7,7 @@ def test_repositoryactioncount(app):
|
||||||
database.RepositorySearchScore.delete().execute()
|
database.RepositorySearchScore.delete().execute()
|
||||||
|
|
||||||
rac = RepositoryActionCountWorker()
|
rac = RepositoryActionCountWorker()
|
||||||
rac._count_repository_actions()
|
while rac._count_repository_actions():
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue