auto: black run
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
from migrate.versioning.shell import main
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(debug='False')
|
||||
if __name__ == "__main__":
|
||||
main(debug="False")
|
||||
|
||||
@@ -3,14 +3,16 @@ from sqlalchemy import Table, Column, Integer, Unicode, Boolean, MetaData, Forei
|
||||
meta = MetaData()
|
||||
|
||||
user = Table(
|
||||
"users", meta,
|
||||
"users",
|
||||
meta,
|
||||
Column("id", Integer, primary_key=True),
|
||||
Column("opt_out", Boolean, default=False, nullable=False),
|
||||
Column("name", Unicode(120), nullable=False, index=True, unique=True)
|
||||
Column("name", Unicode(120), nullable=False, index=True, unique=True),
|
||||
)
|
||||
|
||||
repository = Table(
|
||||
"repositories", meta,
|
||||
"repositories",
|
||||
meta,
|
||||
Column("id", Integer, primary_key=True),
|
||||
Column("user_id", ForeignKey("users.id"), nullable=False),
|
||||
Column("name", Unicode(120), nullable=False, index=True),
|
||||
@@ -26,16 +28,17 @@ repository = Table(
|
||||
|
||||
|
||||
analyze_task = Table(
|
||||
"analyze_tasks", meta,
|
||||
Column("id", Integer, primary_key=True),
|
||||
Column("repository_id", ForeignKey("repositories.id"), nullable=False, index=True),
|
||||
Column("duration", Float, nullable=False, index=True),
|
||||
Column("created_at", Integer, nullable=False, index=True),
|
||||
Column("worker", Unicode(80), nullable=False, index=True),
|
||||
Column("level", Integer, nullable=False),
|
||||
Column("url", Unicode(200), nullable=False),
|
||||
Column("improvement_absolute", Integer, nullable=False, index=True),
|
||||
Column("improvement_relative", Float, nullable=False, index=True)
|
||||
"analyze_tasks",
|
||||
meta,
|
||||
Column("id", Integer, primary_key=True),
|
||||
Column("repository_id", ForeignKey("repositories.id"), nullable=False, index=True),
|
||||
Column("duration", Float, nullable=False, index=True),
|
||||
Column("created_at", Integer, nullable=False, index=True),
|
||||
Column("worker", Unicode(80), nullable=False, index=True),
|
||||
Column("level", Integer, nullable=False),
|
||||
Column("url", Unicode(200), nullable=False),
|
||||
Column("improvement_absolute", Integer, nullable=False, index=True),
|
||||
Column("improvement_relative", Float, nullable=False, index=True),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -7,9 +7,7 @@ def _get_indices(meta):
|
||||
meta.reflect()
|
||||
Users = Table("users", meta, autoload=True, autoload_with=meta.bind)
|
||||
Repositories = Table("users", meta, autoload=True, autoload_with=meta.bind)
|
||||
return [
|
||||
Index("repositories_name_unique_id", Users.c.id, Repositories.c.name, unique=True)
|
||||
]
|
||||
return [Index("repositories_name_unique_id", Users.c.id, Repositories.c.name, unique=True)]
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
|
||||
@@ -16,9 +16,7 @@ def _get_column():
|
||||
def _get_indices(meta):
|
||||
meta.reflect()
|
||||
AnalyzeTask = Table("analyze_tasks", meta, autoload=True, autoload_with=meta.bind)
|
||||
return [
|
||||
Index("analyze_tasks_status_idx", AnalyzeTask.c.status, unique=False)
|
||||
]
|
||||
return [Index("analyze_tasks_status_idx", AnalyzeTask.c.status, unique=False)]
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
|
||||
@@ -46,11 +46,7 @@ def _process_main(results_queue: queue.Queue, task: AnalyzeTask):
|
||||
res["status"] = "success"
|
||||
except Exception as err:
|
||||
logging.exception(f"Error {err} with {task.url}")
|
||||
res = {
|
||||
"status": "error",
|
||||
"message": str(err),
|
||||
"task_id": task.task_id
|
||||
}
|
||||
res = {"status": "error", "message": str(err), "task_id": task.task_id}
|
||||
results_queue.put(res)
|
||||
|
||||
|
||||
@@ -58,10 +54,7 @@ def rabbit_callback(ch, method, properties, body):
|
||||
task = AnalyzeTask.from_data(json.loads(body))
|
||||
logging.info(f"New task url: {task.url}, level: {task.level}")
|
||||
res_queue = multiprocessing.Queue()
|
||||
method_process = multiprocessing.Process(
|
||||
target=_process_main,
|
||||
args=(res_queue, task)
|
||||
)
|
||||
method_process = multiprocessing.Process(target=_process_main, args=(res_queue, task))
|
||||
method_process.start()
|
||||
for delay in delay_generator():
|
||||
ch.connection.sleep(delay)
|
||||
|
||||
15
src/db.py
15
src/db.py
@@ -49,16 +49,21 @@ class AnalyzeTask(Base):
|
||||
__tablename__ = "analyze_tasks"
|
||||
id = Column(Integer, primary_key=True)
|
||||
repository_id = Column(ForeignKey("repositories.id"), nullable=False)
|
||||
status = Column(Integer, default=TaskStatus.InQueue,nullable=False, index=True)
|
||||
status = Column(Integer, default=TaskStatus.InQueue, nullable=False, index=True)
|
||||
repository = relationship(Repository)
|
||||
clone_duration = Column(Float, default=0., nullable=False, index=True)
|
||||
duration = Column(Float, default=0., nullable=False, index=True)
|
||||
created_at = Column(Integer, default=lambda: int(datetime.datetime.now().timestamp()), nullable=False, index=True)
|
||||
clone_duration = Column(Float, default=0.0, nullable=False, index=True)
|
||||
duration = Column(Float, default=0.0, nullable=False, index=True)
|
||||
created_at = Column(
|
||||
Integer,
|
||||
default=lambda: int(datetime.datetime.now().timestamp()),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
worker = Column(Unicode(80), default="", nullable=False, index=True)
|
||||
level = Column(Integer, default=0, nullable=False)
|
||||
url = Column(Unicode(200), default="", nullable=False)
|
||||
improvement_absolute = Column(Integer, default=0, nullable=False, index=True)
|
||||
improvement_relative = Column(Float, default=0., nullable=False, index=True)
|
||||
improvement_relative = Column(Float, default=0.0, nullable=False, index=True)
|
||||
|
||||
|
||||
_engine = create_engine(DB_PATH)
|
||||
|
||||
@@ -8,7 +8,7 @@ from src.settings import GIT_PRIVATE_KEY_PATH
|
||||
_logger = logging.getLogger(__name__)
|
||||
_logger.addHandler(logging.NullHandler())
|
||||
|
||||
os.environ['GIT_SSH_COMMAND'] = f"ssh -i {shlex.quote(GIT_PRIVATE_KEY_PATH)} -o IdentitiesOnly=yes"
|
||||
os.environ["GIT_SSH_COMMAND"] = f"ssh -i {shlex.quote(GIT_PRIVATE_KEY_PATH)} -o IdentitiesOnly=yes"
|
||||
|
||||
|
||||
def _check_preconditions():
|
||||
@@ -30,9 +30,7 @@ def commit_and_push(repo_path: str, commit_message: str):
|
||||
subprocess.check_call(
|
||||
["git", "commit", "-m", commit_message], cwd=repo_path, stdout=subprocess.DEVNULL
|
||||
)
|
||||
branches = subprocess.check_output(
|
||||
["git", "branch"], cwd=repo_path
|
||||
).decode("utf-8")
|
||||
branches = subprocess.check_output(["git", "branch"], cwd=repo_path).decode("utf-8")
|
||||
current_branch = next(filter(lambda x: x.startswith("*"), branches.splitlines()))[1:].strip()
|
||||
_logger.info(f"pushing branch {current_branch} in repo {repo_path}")
|
||||
subprocess.check_call(
|
||||
|
||||
@@ -82,13 +82,12 @@ def create_analyze_task(url: str, level: int, task_id: Optional[int] = None) ->
|
||||
|
||||
|
||||
def create_analyze_response(
|
||||
task: AnalyzeTask,
|
||||
initial_size: int,
|
||||
final_size: int,
|
||||
duration: float,
|
||||
worker: str = platform.node(),
|
||||
clone_duration: float = 0,
|
||||
|
||||
task: AnalyzeTask,
|
||||
initial_size: int,
|
||||
final_size: int,
|
||||
duration: float,
|
||||
worker: str,
|
||||
clone_duration: float = 0,
|
||||
) -> AnalyzeResponse:
|
||||
res = AnalyzeResponse()
|
||||
res.created_at = task.created_at
|
||||
|
||||
Reference in New Issue
Block a user