Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

17505 Create a loop to attempt retrieval of payment records from the payment queue callback up to a maximum of five times #1417

Merged
merged 21 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e53e7d8
allow to delay at most 1 sec when retrieving payment unsuccessful in …
eve-git Sep 14, 2023
7abcb93
allow to delay at most 1 sec when retrieving payment unsuccessful in …
eve-git Sep 14, 2023
25faad9
allow to delay at most 1 sec when retrieving payment unsuccessful in …
eve-git Sep 14, 2023
11a627a
allow to delay at most 1 sec when retrieving payment unsuccessful in …
eve-git Sep 14, 2023
2882238
allow to delay at most 1 sec when retrieving payment unsuccessful in …
eve-git Sep 14, 2023
a83b573
allow to delay at most 1 sec when retrieving payment unsuccessful in …
eve-git Sep 14, 2023
df71b6b
update requirement.txt in order to pass build
eve-git Sep 14, 2023
60a44ad
Merge branch 'bcgov:main' into 17505
eve-git Sep 15, 2023
5b16c9f
allow to delay at most 1 sec when retrieving payment unsuccessful in …
eve-git Sep 14, 2023
c3dc8e2
allow to delay at most 1 sec when retrieving payment unsuccessful in …
eve-git Sep 14, 2023
2d5c7c3
allow to delay at most 1 sec when retrieving payment unsuccessful in …
eve-git Sep 14, 2023
9f72d8e
allow to delay at most 1 sec when retrieving payment unsuccessful in …
eve-git Sep 14, 2023
e8af876
allow to delay at most 1 sec when retrieving payment unsuccessful in …
eve-git Sep 14, 2023
d65030f
allow to delay at most 1 sec when retrieving payment unsuccessful in …
eve-git Sep 14, 2023
ceb84bc
update requirement.txt in order to pass build
eve-git Sep 14, 2023
2b10ee8
update requirements.txt
eve-git Sep 15, 2023
d4ab0eb
Merge branch '17505' of https://github.com/eve-git/namex into 17505
eve-git Sep 15, 2023
df41efb
update requirements
eve-git Sep 15, 2023
ce66a32
update requirements
eve-git Sep 15, 2023
25bf1fc
correct the unexpected change
eve-git Sep 15, 2023
d23cee3
raise exception if the payment record cannot be found.
eve-git Sep 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions services/namex-pay/requirements.txt
ozamani9gh marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
Flask==1.1.2
itsdangerous==1.1.0
jsonschema==3.2.0
python-dotenv==0.17.1
sentry-sdk[flask]
jsonschema==4.16.0
python-dotenv==0.21.0
sentry-sdk[flask]==1.20.0
asyncio-nats-client==0.11.4
asyncio-nats-streaming==0.4.0
pycountry==20.7.3
pycountry==22.3.5
Werkzeug==1.0.1
nest_asyncio
aiohttp>=3.8.1
attrs==20.3.0
certifi==2020.12.5
click==7.1.2
attrs==22.1.0
certifi==2022.9.24
click==8.1.3
Jinja2==2.11.3
MarkupSafe==1.1.1
pyrsistent==0.17.3
six==1.15.0
urllib3==1.26.4
requests==2.25.1
pyrsistent==0.18.1
six==1.16.0
urllib3==1.26.12
requests==2.28.1
protobuf==3.20.1
blinker==1.5
charset-normalizer==2.1.1
idna==3.4
importlib-resources==5.10.0
zipp==3.8.1

git+https://github.com/bcgov/business-schemas.git#egg=registry_schemas
git+https://github.com/bcgov/namex.git#egg=namex&subdirectory=api
Expand Down
2 changes: 1 addition & 1 deletion services/namex-pay/src/namex_pay/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
Development release segment: .devN
"""

__version__ = '0.1.3' # pylint: disable=invalid-name
__version__ = '0.1.4' # pylint: disable=invalid-name
11 changes: 9 additions & 2 deletions services/namex-pay/src/namex_pay/worker.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably throw an exception on line 259, that way the queue will reprocess the message if the retry fails.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seeker25 please review

Copy link
Collaborator

@seeker25 seeker25 Sep 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, you might not need the retry loop with the exception being thrown, but I think this is ok for now.

Would recommend removing lines on 198, 199

Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,14 @@ async def process_payment(pay_msg: dict, flask_app: Flask):
logger.debug('COMPLETED transaction on queue: %s', pay_msg)

if payment_token := pay_msg.get('paymentToken', {}).get('id'):
if payment := Payment.find_by_payment_token(payment_token):

payment = None
counter = 1
while not payment and counter <= 5:
payment = Payment.find_by_payment_token(payment_token)
counter += 1
if not payment:
await asyncio.sleep(0.2)
if payment:
if update_payment := await update_payment_record(payment):
payment = update_payment
# record event
Expand Down Expand Up @@ -252,6 +258,7 @@ async def process_payment(pay_msg: dict, flask_app: Flask):
else:
logger.debug('Queue Error: Unable to find payment record for :%s', pay_msg)
capture_message(f'Queue Error: Unable to find payment record for :{pay_msg}', level='error')
raise QueueException(f'Queue Error: Unable to find payment record for :{pay_msg}')
else:
logger.debug('Queue Error: Missing id :%s', pay_msg)
capture_message(f'Queue Error: Missing id :{pay_msg}', level='error')
Expand Down
Loading