Skip to content

Commit

Permalink
Limit flawless to 10 concurrent git blames so service doesn't fall ov…
Browse files Browse the repository at this point in the history
…er under a flood of errors
  • Loading branch information
jwegan committed Jun 1, 2013
1 parent 1369994 commit 1039378
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions flawless/lib/config/__init__.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
lambda s: [e.strip() for e in s.split(",") if e.strip()], lambda s: [e.strip() for e in s.split(",") if e.strip()],
"When assigning blame to a file, you can explicity only blame " "When assigning blame to a file, you can explicity only blame "
"files whose filepath matches any pattern on this CSV list"), "files whose filepath matches any pattern on this CSV list"),
FlawlessOption("max_concurrent_git_blames", 10, int,
"The maximum number of git blames that can run at the same time"),


# Repository info # Repository info
FlawlessOption("git_cli_path", "git", str, "Path to the git command line utility"), FlawlessOption("git_cli_path", "git", str, "Path to the git command line utility"),
Expand Down
16 changes: 14 additions & 2 deletions flawless/server/service.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def __init__(self, persistent_dict_cls=PersistentDictionary,
self.persistent_dict_cls = persistent_dict_cls self.persistent_dict_cls = persistent_dict_cls
self.time_func = time_func self.time_func = time_func
self.thread_cls = thread_cls self.thread_cls = thread_cls
self.number_of_git_blames_running = 0


self.building_blocks = self._parse_whitelist_file("building_blocks", BuildingBlock) self.building_blocks = self._parse_whitelist_file("building_blocks", BuildingBlock)
self.third_party_whitelist = self._parse_whitelist_file("third_party_whitelist", self.third_party_whitelist = self._parse_whitelist_file("third_party_whitelist",
Expand Down Expand Up @@ -421,8 +422,19 @@ def _record_error(self, request):
# If this error hasn't been reported before, then find the dev responsible # If this error hasn't been reported before, then find the dev responsible
err_info = None err_info = None
if key not in self.errors_seen: if key not in self.errors_seen:
email, last_touched_ts = self.repository.blame(key.filename, key.line_number) # If flawless is being flooded wih errors, limit the number of git blames so the
dev_email = self._get_email(email) if email else "unknown" # service doesn't fall over. We don't use a thread safe counter, because 10
# git blames is just a soft limit
if self.number_of_git_blames_running > config.max_concurrent_git_blames:
log.error("Unable to process %s because %d git blames already running" %
(str(key), self.number_of_git_blames_running))
return
try:
self.number_of_git_blames_running += 1
email, last_touched_ts = self.repository.blame(key.filename, key.line_number)
finally:
self.number_of_git_blames_running -= 1
dev_email = self._get_email(email)
last_touched_ts = last_touched_ts or 0 last_touched_ts = last_touched_ts or 0


cur_time = self._convert_epoch_ms(datetime.datetime).strftime("%Y-%m-%d %H:%M:%S") cur_time = self._convert_epoch_ms(datetime.datetime).strftime("%Y-%m-%d %H:%M:%S")
Expand Down

0 comments on commit 1039378

Please sign in to comment.