-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3573 from webcompat/issue/3571/1
Issue #3571: Use bugbug to classify issues
- Loading branch information
Showing
5 changed files
with
198 additions
and
22 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
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,50 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
"""Helpers methods for machine learning classification.""" | ||
|
||
import requests | ||
import time | ||
|
||
from requests.exceptions import ConnectionError | ||
|
||
from webcompat import app | ||
|
||
BUGBUG_HTTP_SERVER = app.config['BUGBUG_HTTP_SERVER'] | ||
CLASSIFIER_PATH = app.config['CLASSIFIER_PATH'] | ||
|
||
|
||
def make_classification_request(issue_number): | ||
"""Make a request to bugbug http service.""" | ||
url = f"{BUGBUG_HTTP_SERVER}/{CLASSIFIER_PATH}/{issue_number}" | ||
headers = {"X-Api-Key": "webcompat"} | ||
response = requests.get(url, headers=headers) | ||
response.raise_for_status() | ||
return response | ||
|
||
|
||
def get_issue_classification(issue_number, retry_count=4, retry_sleep=3): | ||
"""Get issue classification from bugbug. | ||
As classification happens in the background we need to make a second | ||
request to get results, so we're polling the endpoint. | ||
The service returns 202 status if request is still in process | ||
and 200 status if the issue is classified | ||
""" | ||
for _ in range(retry_count): | ||
response = make_classification_request(issue_number) | ||
|
||
if response.status_code == 202: | ||
time.sleep(retry_sleep) | ||
else: | ||
break | ||
else: | ||
total_sleep = retry_count * retry_sleep | ||
msg = f"Couldn't classify issue {issue_number} in {total_sleep} seconds, aborting" # noqa | ||
raise ConnectionError(msg) | ||
|
||
return response.json() |
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