зеркало из https://github.com/mozilla/bugbug.git
Use tenacity instead of implementing a retry function ourselves (#1272)
Fixes #1234
This commit is contained in:
Родитель
d83d62d82a
Коммит
7a1d2457ef
|
@ -4,4 +4,4 @@ include_trailing_comma=True
|
|||
force_grid_wrap=0
|
||||
use_parentheses=True
|
||||
line_length=88
|
||||
known_third_party = apispec,apispec_webframeworks,cerberus,dateutil,flask,flask_cors,hglib,imblearn,joblib,jsone,jsonschema,libmozdata,lmdb,marshmallow,matplotlib,microannotate,models,numpy,orjson,pandas,pkg_resources,pydriller,pyemd,pytest,redis,requests,responses,rq,scipy,setuptools,shap,sklearn,tabulate,taskcluster,tqdm,xgboost,yaml,zstandard
|
||||
known_third_party = apispec,apispec_webframeworks,cerberus,dateutil,flask,flask_cors,hglib,imblearn,joblib,jsone,jsonschema,libmozdata,lmdb,marshmallow,matplotlib,microannotate,models,numpy,orjson,pandas,pkg_resources,pydriller,pyemd,pytest,redis,requests,responses,rq,scipy,setuptools,shap,sklearn,tabulate,taskcluster,tenacity,tqdm,xgboost,yaml,zstandard
|
||||
|
|
|
@ -9,7 +9,6 @@ import logging
|
|||
import os
|
||||
import socket
|
||||
import tarfile
|
||||
import time
|
||||
from collections import deque
|
||||
from contextlib import contextmanager
|
||||
|
||||
|
@ -204,18 +203,6 @@ def download_and_load_model(model_name):
|
|||
return get_model_class(model_name).load(path)
|
||||
|
||||
|
||||
def retry(operation, retries=5, wait_between_retries=30):
|
||||
while True:
|
||||
try:
|
||||
return operation()
|
||||
except Exception:
|
||||
retries -= 1
|
||||
if retries == 0:
|
||||
raise
|
||||
|
||||
time.sleep(wait_between_retries)
|
||||
|
||||
|
||||
def zstd_compress(path):
|
||||
cctx = zstandard.ZstdCompressor()
|
||||
with open(path, "rb") as input_f:
|
||||
|
|
|
@ -18,6 +18,7 @@ scipy==1.4.1
|
|||
shap[plots]==0.34.0
|
||||
tabulate==0.8.6
|
||||
taskcluster==24.2.0
|
||||
tenacity==6.0.0
|
||||
tqdm==4.42.1
|
||||
xgboost==0.90
|
||||
zstandard==0.13.0
|
||||
|
|
|
@ -19,6 +19,7 @@ import matplotlib
|
|||
import numpy as np
|
||||
import requests
|
||||
import shap
|
||||
import tenacity
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from libmozdata import vcs_map
|
||||
from libmozdata.phabricator import PhabricatorAPI
|
||||
|
@ -29,7 +30,6 @@ from bugbug.utils import (
|
|||
download_and_load_model,
|
||||
download_check_etag,
|
||||
get_secret,
|
||||
retry,
|
||||
to_array,
|
||||
zstd_decompress,
|
||||
)
|
||||
|
@ -189,26 +189,32 @@ class CommitClassifier(object):
|
|||
logger.info(f"Cloning {repo_url}...")
|
||||
|
||||
if not os.path.exists(repo_dir):
|
||||
retry(
|
||||
tenacity.retry(
|
||||
lambda: subprocess.run(
|
||||
["git", "clone", "--quiet", repo_url, repo_dir], check=True
|
||||
)
|
||||
)
|
||||
),
|
||||
wait=tenacity.wait_fixed(30),
|
||||
stop=tenacity.stop_after_attempt(5),
|
||||
)()
|
||||
|
||||
retry(
|
||||
tenacity.retry(
|
||||
lambda: subprocess.run(
|
||||
["git", "pull", "--quiet", repo_url, "master"],
|
||||
cwd=repo_dir,
|
||||
capture_output=True,
|
||||
check=True,
|
||||
)
|
||||
)
|
||||
),
|
||||
wait=tenacity.wait_fixed(30),
|
||||
stop=tenacity.stop_after_attempt(5),
|
||||
)()
|
||||
|
||||
retry(
|
||||
tenacity.retry(
|
||||
lambda: subprocess.run(
|
||||
["git", "checkout", rev], cwd=repo_dir, capture_output=True, check=True
|
||||
)
|
||||
)
|
||||
),
|
||||
wait=tenacity.wait_fixed(30),
|
||||
stop=tenacity.stop_after_attempt(5),
|
||||
)()
|
||||
|
||||
def update_commit_db(self):
|
||||
repository.clone(self.repo_dir)
|
||||
|
|
|
@ -5,10 +5,11 @@ import os
|
|||
import subprocess
|
||||
from logging import INFO, basicConfig, getLogger
|
||||
|
||||
import tenacity
|
||||
from microannotate import generator
|
||||
|
||||
from bugbug import db, repository
|
||||
from bugbug.utils import ThreadPoolExecutorResult, get_secret, retry
|
||||
from bugbug.utils import ThreadPoolExecutorResult, get_secret
|
||||
|
||||
basicConfig(level=INFO)
|
||||
logger = getLogger(__name__)
|
||||
|
@ -61,11 +62,13 @@ class MicroannotateGenerator(object):
|
|||
else:
|
||||
executor.submit(self.init_git_repo)
|
||||
|
||||
retry(
|
||||
tenacity.retry(
|
||||
lambda: subprocess.run(
|
||||
["git", "config", "--global", "http.postBuffer", "12M"], check=True
|
||||
)
|
||||
)
|
||||
),
|
||||
wait=tenacity.wait_fixed(30),
|
||||
stop=tenacity.stop_after_attempt(5),
|
||||
)()
|
||||
|
||||
push_args = ["git", "push", repo_push_url, "master"]
|
||||
if is_old_version:
|
||||
|
@ -81,7 +84,11 @@ class MicroannotateGenerator(object):
|
|||
remove_comments=self.remove_comments,
|
||||
)
|
||||
|
||||
retry(lambda: subprocess.run(push_args, cwd=self.git_repo_path, check=True))
|
||||
tenacity.retry(
|
||||
lambda: subprocess.run(push_args, cwd=self.git_repo_path, check=True),
|
||||
wait=tenacity.wait_fixed(30),
|
||||
stop=tenacity.stop_after_attempt(5),
|
||||
)()
|
||||
|
||||
def init_git_repo(self):
|
||||
subprocess.run(["git", "init", self.git_repo_path], check=True)
|
||||
|
@ -93,22 +100,26 @@ class MicroannotateGenerator(object):
|
|||
)
|
||||
|
||||
def clone_git_repo(self):
|
||||
retry(
|
||||
tenacity.retry(
|
||||
lambda: subprocess.run(
|
||||
["git", "clone", "--quiet", self.repo_url, self.git_repo_path],
|
||||
check=True,
|
||||
)
|
||||
)
|
||||
),
|
||||
wait=tenacity.wait_fixed(30),
|
||||
stop=tenacity.stop_after_attempt(5),
|
||||
)()
|
||||
|
||||
try:
|
||||
retry(
|
||||
tenacity.retry(
|
||||
lambda: subprocess.run(
|
||||
["git", "pull", "--quiet", self.repo_url, "master"],
|
||||
cwd=self.git_repo_path,
|
||||
capture_output=True,
|
||||
check=True,
|
||||
)
|
||||
)
|
||||
),
|
||||
wait=tenacity.wait_fixed(30),
|
||||
stop=tenacity.stop_after_attempt(5),
|
||||
)()
|
||||
except subprocess.CalledProcessError as e:
|
||||
# When the repo is empty.
|
||||
if b"Couldn't find remote ref master" in e.stdout:
|
||||
|
|
|
@ -14,6 +14,7 @@ from logging import INFO, basicConfig, getLogger
|
|||
|
||||
import dateutil.parser
|
||||
import hglib
|
||||
import tenacity
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from libmozdata import vcs_map
|
||||
from microannotate import utils as microannotate_utils
|
||||
|
@ -26,7 +27,7 @@ from bugbug.models.regressor import (
|
|||
BUG_INTRODUCING_COMMITS_DB,
|
||||
TOKENIZED_BUG_INTRODUCING_COMMITS_DB,
|
||||
)
|
||||
from bugbug.utils import download_and_load_model, retry, zstd_compress
|
||||
from bugbug.utils import download_and_load_model, zstd_compress
|
||||
|
||||
basicConfig(level=INFO)
|
||||
logger = getLogger(__name__)
|
||||
|
@ -83,19 +84,23 @@ class RegressorFinder(object):
|
|||
|
||||
def clone_git_repo(self, repo_url, repo_dir):
|
||||
if not os.path.exists(repo_dir):
|
||||
retry(
|
||||
tenacity.retry(
|
||||
lambda: subprocess.run(
|
||||
["git", "clone", "--quiet", repo_url, repo_dir], check=True
|
||||
)
|
||||
),
|
||||
wait=tenacity.wait_fixed(30),
|
||||
stop=tenacity.stop_after_attempt(5),
|
||||
)
|
||||
|
||||
retry(
|
||||
tenacity.retry(
|
||||
lambda: subprocess.run(
|
||||
["git", "pull", "--quiet", repo_url, "master"],
|
||||
cwd=repo_dir,
|
||||
capture_output=True,
|
||||
check=True,
|
||||
)
|
||||
),
|
||||
wait=tenacity.wait_fixed(30),
|
||||
stop=tenacity.stop_after_attempt(5),
|
||||
)
|
||||
|
||||
def init_mapping(self):
|
||||
|
|
Загрузка…
Ссылка в новой задаче