From 88a99205b3b7f65b5a6d0dae1a966f94ccb7be9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20L=C3=B3pez?= Date: Fri, 28 Feb 2020 13:44:11 -0600 Subject: [PATCH 1/9] newrelic config --- Dockerfile | 2 +- Makefile | 2 +- arcusd/daemon/tasks.py | 7 +++++++ arcusd/daemon/tasks_sync.py | 3 +++ env.template | 1 + requirements.txt | 1 + 6 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index cfe9215..f255151 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,4 +10,4 @@ RUN make install ADD . /arcusd/ RUN pip install -e . -CMD celery worker -A arcusd.daemon.tasks --loglevel=info -c ${ARCUSD_WORKERS:-0} +CMD NEW_RELIC_LICENSE_KEY=${NEW_RELIC_LICENSE_KEY} NEW_RELIC_APP_NAME=arcusd newrelic-admin run-program celery worker -A arcusd.daemon.tasks --loglevel=info -c ${ARCUSD_WORKERS:-0} diff --git a/Makefile b/Makefile index 867cd51..e8da157 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ install: pip install -q -r requirements.txt install-dev: install - pip install -q -r requirements-dev.txt + pip install -r requirements-dev.txt venv: $(PYTHON) -m venv --prompt arcusd venv diff --git a/arcusd/daemon/tasks.py b/arcusd/daemon/tasks.py index dede55e..1aa1108 100644 --- a/arcusd/daemon/tasks.py +++ b/arcusd/daemon/tasks.py @@ -1,5 +1,7 @@ from typing import Optional +import newrelic.agent + import arcusd.arcusactions from arcusd.data_access.providers_mapping import get_biller_id from .celery_app import app @@ -7,6 +9,7 @@ from ..types import OperationType +@newrelic.agent.background_task() @app.task def topup(request_id: str, service_provider_code: str, phone_number: str, amount: int, currency: str = 'MXN', @@ -17,6 +20,7 @@ def topup(request_id: str, service_provider_code: str, phone_number: str, currency, name_on_account) +@newrelic.agent.background_task() @app.task def query_bill(request_id: str, service_provider_code: str, account_number: str): @@ -24,12 +28,14 @@ def query_bill(request_id: str, service_provider_code: str, get_biller_id(service_provider_code), account_number) +@newrelic.agent.background_task() @app.task def pay_bill_id(request_id: str, bill_id: int): execute_op(request_id, OperationType.payment, arcusd.arcusactions.pay_bill_id, bill_id) +@newrelic.agent.background_task() @app.task def pay_bill(request_id: str, service_provider_code: str, account_number: str, amount: Optional[int] = None): @@ -38,6 +44,7 @@ def pay_bill(request_id: str, service_provider_code: str, account_number: str, amount) +@newrelic.agent.background_task() @app.task def cancel_transaction(request_id: str, transaction_id: int): execute_op(request_id, OperationType.payment, diff --git a/arcusd/daemon/tasks_sync.py b/arcusd/daemon/tasks_sync.py index c05fee9..5bcc22a 100644 --- a/arcusd/daemon/tasks_sync.py +++ b/arcusd/daemon/tasks_sync.py @@ -1,3 +1,5 @@ +import newrelic.agent + import arcusd from arcusd.data_access.providers_mapping import get_biller_id from .celery_app import app @@ -5,6 +7,7 @@ from ..types import OperationType +@newrelic.agent.background_task() @app.task def query_bill(service_provider_code: str, account_number: str) -> dict: op_info = execute_op(None, OperationType.query, diff --git a/env.template b/env.template index ecb866a..3ed78d6 100644 --- a/env.template +++ b/env.template @@ -12,3 +12,4 @@ ARCUSD_CALLBACK_SECRET=JKLMNOPQRS ARCUSD_SENTRY_DSN=https://3@sentry.io/1 ARCUSD_WORKERS=0 TOPUP_BILLERS=20,30,40 +NEW_RELIC_LICENSE_KEY=foo diff --git a/requirements.txt b/requirements.txt index ae3aed7..60a0b7a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ sentry-sdk==0.10.2 requests==2.21.0 click==7.0 dataclasses +newrelic>=5.4.1.134,<5.5.0.0 From 19febe14014fa64c9af9e603d2532965cfe1b983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20L=C3=B3pez?= Date: Fri, 28 Feb 2020 13:48:45 -0600 Subject: [PATCH 2/9] fix --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e8da157..867cd51 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ install: pip install -q -r requirements.txt install-dev: install - pip install -r requirements-dev.txt + pip install -q -r requirements-dev.txt venv: $(PYTHON) -m venv --prompt arcusd venv From 49dc425081e04e1e5f8a2bbbb2384fa6f0710daf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20L=C3=B3pez?= Date: Tue, 10 Mar 2020 19:15:48 -0600 Subject: [PATCH 3/9] python3.7 --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index f255151..4d76a8b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM cuenca/python:latest +FROM python:3.7 LABEL maintainer="dev@cuenca.com" # Install app @@ -10,4 +10,4 @@ RUN make install ADD . /arcusd/ RUN pip install -e . -CMD NEW_RELIC_LICENSE_KEY=${NEW_RELIC_LICENSE_KEY} NEW_RELIC_APP_NAME=arcusd newrelic-admin run-program celery worker -A arcusd.daemon.tasks --loglevel=info -c ${ARCUSD_WORKERS:-0} +CMD NEW_RELIC_LICENSE_KEY=${NEW_RELIC_LICENSE_KEY:-} NEW_RELIC_APP_NAME=arcusd newrelic-admin run-program celery worker -A arcusd.daemon.tasks --loglevel=info -c ${ARCUSD_WORKERS:-0} From 5f93d95358d4e48fbbcd11b489a1a3dfb425f375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20L=C3=B3pez?= Date: Tue, 10 Mar 2020 19:16:47 -0600 Subject: [PATCH 4/9] fix command --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 4d76a8b..3a94162 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,4 +10,4 @@ RUN make install ADD . /arcusd/ RUN pip install -e . -CMD NEW_RELIC_LICENSE_KEY=${NEW_RELIC_LICENSE_KEY:-} NEW_RELIC_APP_NAME=arcusd newrelic-admin run-program celery worker -A arcusd.daemon.tasks --loglevel=info -c ${ARCUSD_WORKERS:-0} +CMD NEW_RELIC_LICENSE_KEY=$NEW_RELIC_LICENSE_KEY NEW_RELIC_APP_NAME=arcusd newrelic-admin run-program celery worker -A arcusd.daemon.tasks --loglevel=info -c ${ARCUSD_WORKERS:-5} From 9f74c8338e4fc71d354f3093d60dd10c221a165e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20L=C3=B3pez?= Date: Thu, 16 Apr 2020 13:36:57 -0500 Subject: [PATCH 5/9] change docker image --- Dockerfile | 2 +- arcusd/daemon/__init__.py | 6 ++++-- arcusd/daemon/tasks.py | 10 +++++----- arcusd/daemon/tasks_sync.py | 2 +- env.template | 1 + requirements-dev.txt | 10 +++++----- requirements.txt | 2 +- 7 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3a94162..114dd64 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7 +FROM python:3.6 LABEL maintainer="dev@cuenca.com" # Install app diff --git a/arcusd/daemon/__init__.py b/arcusd/daemon/__init__.py index 1a71fa0..770066b 100644 --- a/arcusd/daemon/__init__.py +++ b/arcusd/daemon/__init__.py @@ -3,5 +3,7 @@ import sentry_sdk from sentry_sdk.integrations.celery import CeleryIntegration -sentry_sdk.init(os.environ['ARCUSD_SENTRY_DSN'], - integrations=[CeleryIntegration()]) + +if os.environ.get('ARCUSD_PROD', 'true') == 'true': + sentry_sdk.init(os.environ['ARCUSD_SENTRY_DSN'], + integrations=[CeleryIntegration()]) diff --git a/arcusd/daemon/tasks.py b/arcusd/daemon/tasks.py index 1aa1108..27e8e60 100644 --- a/arcusd/daemon/tasks.py +++ b/arcusd/daemon/tasks.py @@ -9,8 +9,8 @@ from ..types import OperationType -@newrelic.agent.background_task() @app.task +@newrelic.agent.background_task() def topup(request_id: str, service_provider_code: str, phone_number: str, amount: int, currency: str = 'MXN', name_on_account: Optional[str] = None): @@ -20,23 +20,23 @@ def topup(request_id: str, service_provider_code: str, phone_number: str, currency, name_on_account) -@newrelic.agent.background_task() @app.task +@newrelic.agent.background_task() def query_bill(request_id: str, service_provider_code: str, account_number: str): execute_op(request_id, OperationType.query, arcusd.arcusactions.query_bill, get_biller_id(service_provider_code), account_number) -@newrelic.agent.background_task() @app.task +@newrelic.agent.background_task() def pay_bill_id(request_id: str, bill_id: int): execute_op(request_id, OperationType.payment, arcusd.arcusactions.pay_bill_id, bill_id) -@newrelic.agent.background_task() @app.task +@newrelic.agent.background_task() def pay_bill(request_id: str, service_provider_code: str, account_number: str, amount: Optional[int] = None): execute_op(request_id, OperationType.payment, arcusd.arcusactions.pay_bill, @@ -44,8 +44,8 @@ def pay_bill(request_id: str, service_provider_code: str, account_number: str, amount) -@newrelic.agent.background_task() @app.task +@newrelic.agent.background_task() def cancel_transaction(request_id: str, transaction_id: int): execute_op(request_id, OperationType.payment, arcusd.arcusactions.cancel_transaction, transaction_id) diff --git a/arcusd/daemon/tasks_sync.py b/arcusd/daemon/tasks_sync.py index 5bcc22a..12dda4e 100644 --- a/arcusd/daemon/tasks_sync.py +++ b/arcusd/daemon/tasks_sync.py @@ -7,8 +7,8 @@ from ..types import OperationType -@newrelic.agent.background_task() @app.task +@newrelic.agent.background_task() def query_bill(service_provider_code: str, account_number: str) -> dict: op_info = execute_op(None, OperationType.query, arcusd.arcusactions.query_bill, diff --git a/env.template b/env.template index 3ed78d6..d69ee8c 100644 --- a/env.template +++ b/env.template @@ -13,3 +13,4 @@ ARCUSD_SENTRY_DSN=https://3@sentry.io/1 ARCUSD_WORKERS=0 TOPUP_BILLERS=20,30,40 NEW_RELIC_LICENSE_KEY=foo +MULTIDICT_NO_EXTENSIONS=1 diff --git a/requirements-dev.txt b/requirements-dev.txt index 335e4e2..c3132f3 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,5 @@ -coveralls -pycodestyle -pytest -pytest-vcr==1.0.1 -ipython +coveralls==1.8.2 +pycodestyle==2.5.0 +pytest==5.2.0 +pytest-vcr==1.0.2 +ipython==7.8.0 diff --git a/requirements.txt b/requirements.txt index 60a0b7a..a16f382 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ arcus==1.2.0 celery>=4.2,<4.3 pymongo==3.7.2 -sentry-sdk==0.10.2 +sentry-sdk==0.14.3 requests==2.21.0 click==7.0 dataclasses From 5ace93bde738b5fc86e1595f6616430e495da172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20L=C3=B3pez?= Date: Thu, 16 Apr 2020 15:29:45 -0500 Subject: [PATCH 6/9] env var --- env.template | 1 + 1 file changed, 1 insertion(+) diff --git a/env.template b/env.template index d69ee8c..62530da 100644 --- a/env.template +++ b/env.template @@ -14,3 +14,4 @@ ARCUSD_WORKERS=0 TOPUP_BILLERS=20,30,40 NEW_RELIC_LICENSE_KEY=foo MULTIDICT_NO_EXTENSIONS=1 +ARCUSD_PROD=false \ No newline at end of file From 8aa982fa3395348a3ee7451fe3a540aa1e81210c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20L=C3=B3pez?= Date: Thu, 16 Apr 2020 15:43:35 -0500 Subject: [PATCH 7/9] upgrade packages --- env.template | 2 +- requirements-dev.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/env.template b/env.template index 62530da..90ba00b 100644 --- a/env.template +++ b/env.template @@ -14,4 +14,4 @@ ARCUSD_WORKERS=0 TOPUP_BILLERS=20,30,40 NEW_RELIC_LICENSE_KEY=foo MULTIDICT_NO_EXTENSIONS=1 -ARCUSD_PROD=false \ No newline at end of file +ARCUSD_PROD=false diff --git a/requirements-dev.txt b/requirements-dev.txt index c3132f3..81e7fc1 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,4 +1,4 @@ -coveralls==1.8.2 +coveralls==2.0.0 pycodestyle==2.5.0 pytest==5.2.0 pytest-vcr==1.0.2 From c517fca6b64473376777ed4264b46a4348737258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20L=C3=B3pez?= Date: Thu, 16 Apr 2020 17:28:58 -0500 Subject: [PATCH 8/9] fix env vars --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 114dd64..a11f0fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,4 +10,4 @@ RUN make install ADD . /arcusd/ RUN pip install -e . -CMD NEW_RELIC_LICENSE_KEY=$NEW_RELIC_LICENSE_KEY NEW_RELIC_APP_NAME=arcusd newrelic-admin run-program celery worker -A arcusd.daemon.tasks --loglevel=info -c ${ARCUSD_WORKERS:-5} +CMD newrelic-admin run-program celery worker -A arcusd.daemon.tasks --loglevel=info -c ${ARCUSD_WORKERS:-5} From ea53f4c36f8e83e820c18c606ef66736a5d6331d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20L=C3=B3pez?= Date: Thu, 16 Apr 2020 17:48:29 -0500 Subject: [PATCH 9/9] back to cuenca/python --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a11f0fd..75e3122 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.6 +FROM cuenca/python:0.0.1 LABEL maintainer="dev@cuenca.com" # Install app