Skip to content

Commit

Permalink
fix: Use Jobs api for book-keeping task. (#739)
Browse files Browse the repository at this point in the history
* Add call to jobs api.

* Added Ingestion URL.

* Updated utils and worker and used utils functionality for bookkeeping.

* Rebased.

* Address review comment.

* Added try except block on trigger_workflow.
  • Loading branch information
rafiu007 authored Mar 22, 2021
1 parent c07d525 commit 1a0e89d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
31 changes: 19 additions & 12 deletions bayesian/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from f8a_worker.setup_celery import init_celery
from .default_config import STACK_ANALYSIS_REQUEST_TIMEOUT
from sqlalchemy.exc import SQLAlchemyError
from f8a_utils.ingestion_utils import trigger_workerflow

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -65,20 +66,26 @@ def get_user_email(user_profile):

def create_component_bookkeeping(ecosystem, packages_list, request_args, headers):
"""Run the component analysis for given ecosystem+package+version."""
args = {
'external_request_id': headers.get('X-Request-Id', None),
'data': {
'api_name': 'component_analyses_post',
'manifest_hash': request_args.get('utm_content', None),
'ecosystem': ecosystem,
'packages_list': packages_list,
'user_id': headers.get('uuid', None),
'user_agent': headers.get('User-Agent', None),
'source': request_args.get('utm_source', None),
'telemetry_id': headers.get('X-Telemetry-Id', None)
payload = {
"external_request_id": headers.get('X-Request-Id', None),
"flowname": "componentApiFlow",
"data": {
"api_name": "component_analyses_post",
"manifest_hash": request_args.get('utm_content', None),
"ecosystem": ecosystem,
"packages_list": packages_list,
"user_id": headers.get('uuid', None),
"user_agent": headers.get('User-Agent', None),
"source": request_args.get('utm_source', None),
"telemetry_id": headers.get('X-Telemetry-Id', None)
}
}
return server_run_flow('componentApiFlow', args)

try:
trigger_workerflow(payload)
except Exception as e:
logger.error('Failed to trigger worker flow for payload %s with error %s',
payload, e)


def server_create_analysis(ecosystem, package, version, user_profile,
Expand Down
4 changes: 2 additions & 2 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ gevent
#packages discovered after running the image on cluster
psycopg2-binary

f8a_worker @ git+https://github.com/fabric8-analytics/fabric8-analytics-worker.git@af1680a#egg=f8a_worker
f8a_worker @ git+https://github.com/fabric8-analytics/fabric8-analytics-worker.git@c74145b#egg=f8a_worker
f8a_auth @ git+https://github.com/fabric8-analytics/fabric8-analytics-auth.git@5ff9438#egg=fabric8a_auth
f8a_utils @ git+https://github.com/fabric8-analytics/fabric8-analytics-utils.git@839e022#egg=f8a_utils
f8a_version_comparator @ git+https://github.com/fabric8-analytics/fabric8-analytics-version-comparator.git@8a57ac7#egg=f8a_version_comparator
f8a_utils @ git+https://github.com/fabric8-analytics/fabric8-analytics-utils.git@f4fef58#egg=f8a_utils
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ dataclasses==0.8
# via pydantic
deprecated==1.2.11
# via pygithub
git+https://github.com/fabric8-analytics/fabric8-analytics-utils.git@839e022#egg=f8a_utils
git+https://github.com/fabric8-analytics/fabric8-analytics-utils.git@f4fef58#egg=f8a_utils
# via
# -r requirements.in
# f8a-worker
git+https://github.com/fabric8-analytics/fabric8-analytics-version-comparator.git@8a57ac7#egg=f8a_version_comparator
# via
# -r requirements.in
# f8a-utils
git+https://github.com/fabric8-analytics/fabric8-analytics-worker.git@af1680a#egg=f8a_worker
git+https://github.com/fabric8-analytics/fabric8-analytics-worker.git@c74145b#egg=f8a_worker
# via -r requirements.in
git+https://github.com/fabric8-analytics/fabric8-analytics-auth.git@5ff9438#egg=fabric8a_auth
# via -r requirements.in
Expand Down Expand Up @@ -234,7 +234,6 @@ six==1.15.0
# via
# anymarkup-core
# configobj
# cryptography
# flask-appconfig
# flask-cors
# flask-restful
Expand Down

0 comments on commit 1a0e89d

Please sign in to comment.