-
Notifications
You must be signed in to change notification settings - Fork 847
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 #2497 from chaoss/value-worker-migrate-to-task
Value worker migrate to task
- Loading branch information
Showing
9 changed files
with
181 additions
and
13 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
augur/application/schema/alembic/versions/22_alter_repo_labor_unique.py
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,49 @@ | ||
"""Alter repo labor unique | ||
Revision ID: 22 | ||
Revises: 21 | ||
Create Date: 2023-08-25 18:17:22.651191 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
from sqlalchemy.sql import text | ||
import re | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '22' | ||
down_revision = '21' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
|
||
conn = op.get_bind() | ||
|
||
#Remove constraint being initially deferred. | ||
conn.execute(text(f""" | ||
ALTER TABLE "augur_data"."repo_labor" | ||
DROP CONSTRAINT IF EXISTS "rl-unique", | ||
ADD CONSTRAINT "rl-unique" UNIQUE ("repo_id", "rl_analysis_date", "file_path", "file_name"); | ||
""")) | ||
""" | ||
""" | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
conn = op.get_bind() | ||
|
||
#Make unique initially deferred | ||
conn.execute(text(f""" | ||
ALTER TABLE "augur_data"."repo_labor" | ||
DROP CONSTRAINT IF EXISTS "rl-unique", | ||
ADD CONSTRAINT "rl-unique" UNIQUE ("repo_id", "rl_analysis_date", "file_path", "file_name") DEFERRABLE INITIALLY DEFERRED; | ||
""")) | ||
|
||
# ### end Alembic commands ### |
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
Empty file.
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,57 @@ | ||
from datetime import datetime | ||
import logging | ||
import requests | ||
import json | ||
import os | ||
import subprocess | ||
import re | ||
import traceback | ||
from augur.application.db.models import * | ||
from augur.application.db.session import DatabaseSession | ||
from augur.application.config import AugurConfig | ||
from augur.tasks.github.util.github_api_key_handler import GithubApiKeyHandler | ||
from augur.application.db.util import execute_session_query | ||
from augur.tasks.util.worker_util import parse_json_from_subprocess_call | ||
|
||
def value_model(session,repo_git,repo_id, path): | ||
"""Runs scc on repo and stores data in database | ||
:param repo_id: Repository ID | ||
:param path: absolute file path of the Repostiory | ||
""" | ||
|
||
session.logger.info('Generating value data for repo') | ||
session.logger.info(f"Repo ID: {repo_id}, Path: {path}") | ||
session.logger.info('Running scc...') | ||
|
||
path_to_scc = os.environ['HOME'] + '/scc' | ||
|
||
required_output = parse_json_from_subprocess_call(session.logger,['./scc', '-f','json','--by-file', path], cwd=path_to_scc) | ||
|
||
session.logger.info('adding scc data to database... ') | ||
session.logger.debug(f"output: {required_output}") | ||
|
||
to_insert = [] | ||
for record in required_output: | ||
for file in record['Files']: | ||
repo_labor = { | ||
'repo_id': repo_id, | ||
'rl_analysis_date': datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ'), | ||
'programming_language': file['Language'], | ||
'file_path': file['Location'], | ||
'file_name': file['Filename'], | ||
'total_lines': file['Lines'], | ||
'code_lines': file['Code'], | ||
'comment_lines': file['Comment'], | ||
'blank_lines': file['Blank'], | ||
'code_complexity': file['Complexity'], | ||
'repo_url': repo_git, | ||
'tool_source': 'value_model', | ||
'data_source': 'Git', | ||
'data_collection_date': datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ') | ||
} | ||
|
||
to_insert.append(repo_labor) | ||
|
||
session.insert_data(to_insert, RepoLabor, ["repo_id", "rl_analysis_date", "file_path", "file_name" ]) | ||
|
||
session.logger.info(f"Done generating scc data for repo {repo_id} from path {path}") |
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,28 @@ | ||
import logging | ||
import traceback | ||
from augur.application.db.session import DatabaseSession | ||
from augur.tasks.git.scc_value_tasks.core import * | ||
from augur.tasks.init.celery_app import celery_app as celery | ||
from augur.tasks.init.celery_app import AugurFacadeRepoCollectionTask, AugurCoreRepoCollectionTask | ||
from augur.application.db.util import execute_session_query | ||
from augur.application.config import AugurConfig | ||
from augur.tasks.git.util.facade_worker.facade_worker.utilitymethods import get_absolute_repo_path | ||
|
||
|
||
@celery.task(base=AugurFacadeRepoCollectionTask) | ||
def process_scc_value_metrics(repo_git): | ||
|
||
from augur.tasks.init.celery_app import engine | ||
|
||
logger = logging.getLogger(process_scc_value_metrics.__name__) | ||
|
||
with DatabaseSession(logger,engine) as session: | ||
logger.info(f"repo_git: {repo_git}") | ||
|
||
query = session.query(Repo).filter(Repo.repo_git == repo_git) | ||
repo = execute_session_query(query, 'one') | ||
|
||
config = AugurConfig(session.logger, session) | ||
absolute_repo_path = get_absolute_repo_path(config.get_section("Facade")['repo_directory'],repo.repo_id,repo.repo_path,repo.repo_name) | ||
|
||
value_model(session,repo_git,repo.repo_id, absolute_repo_path) |
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