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