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

#174 script to retry failed webhook #18

Merged
merged 11 commits into from
Dec 3, 2021

Conversation

GauravGusain98
Copy link
Contributor

@GauravGusain98 GauravGusain98 commented Dec 2, 2021

DostEducation/RP_IVR_analytics#174

Please complete the following steps and check these boxes before filing your PR:

Types of changes

  • Bug fix (a change which fixes an issue)
  • New feature (a change which adds functionality)

Short description of what this resolves:

  • Added functionality to retry failed webhook logs
  • The created on a date is set to the created on the date of logs.

Checklist:

  • I have performed a self-review of my own code.
  • The code follows the style guidelines of this project.
  • The code changes are passing the CI checks
  • I have documented my code wherever required.
  • The changes requires a change to the documentation.
  • I have updated the documentation based on the my changes.

def get_failed_ivr_transaction_log(self):
failed_ivr_transaction_logs = (
models.IvrCallbackTransactionLog.query.filter_by(processed=False)
.limit(app.config["RETRY_LOGS_LIMIT"])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

using env for limit

Copy link
Member

Choose a reason for hiding this comment

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

@GauravGusain98 though this looks good, the terminology seems a bit confusing.

Initially, I thought we are using this to limit the number of reattempts for retry.

  1. Are we planning to have the retry limit?
  2. Can we change the ENV variable name a bit? maybe like RETRY_LOGS_BATCH_LIMIT

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Yes In case the logs are too many.
  2. 👍

config.py Outdated
@@ -24,7 +24,7 @@
}
# For socket based connection
SQLALCHEMY_DATABASE_URI = (
"postgresql://%(user)s:%(password)s/%(database)s?host=%(connection_name)s/"
"postgresql://%(user)s:%(password)s@/%(database)s?host=%(connection_name)s/"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes related to hotfix. Made another PR for the same.

main.py Outdated
failed_ivr_logs = transaction_log_service.get_failed_ivr_transaction_log()

for log in failed_ivr_logs:
processed = process_form_data(json.loads(log.payload), log.created_on)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

processing each failed log and passing the actual time that be in the created_on column of the new records that will be created.

Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason to pass created_on separately? Isn't it possible to get it from JSON itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@GauravGusain98 GauravGusain98 marked this pull request as ready for review December 2, 2021 11:55

"""PickTime is available only when the call is answered.
The telco code for answered calls is 16.
"""
if request.form["TelcoCode"] == "16":
data["pick_time"] = request.form["PickTime"]
if form_data["TelcoCode"] == "16":
Copy link
Member

Choose a reason for hiding this comment

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

@GauravGusain98 Could you move this to the config file? It was there earlier, but let's clean whatever we can.

def get_failed_ivr_transaction_log(self):
failed_ivr_transaction_logs = (
models.IvrCallbackTransactionLog.query.filter_by(processed=False)
.limit(app.config["RETRY_LOGS_LIMIT"])
Copy link
Member

Choose a reason for hiding this comment

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

@GauravGusain98 though this looks good, the terminology seems a bit confusing.

Initially, I thought we are using this to limit the number of reattempts for retry.

  1. Are we planning to have the retry limit?
  2. Can we change the ENV variable name a bit? maybe like RETRY_LOGS_BATCH_LIMIT

api/services/transaction_log_service.py Show resolved Hide resolved
main.py Outdated
failed_ivr_logs = transaction_log_service.get_failed_ivr_transaction_log()

for log in failed_ivr_logs:
processed = process_form_data(json.loads(log.payload), log.created_on)
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason to pass created_on separately? Isn't it possible to get it from JSON itself?

Copy link
Member

@Satendra-SR Satendra-SR left a comment

Choose a reason for hiding this comment

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

One change is required to reduce the number of DB queries per log processing. Please fix and merge.

main.py Outdated
Comment on lines 43 to 57
for log in failed_ivr_logs:
log.attempts += 1
db.session.add(log)
db.session.commit()

payload = json.loads(log.payload)
payload["log_created_on"] = log.created_on
processed = process_form_data(payload)

if processed is not True:
continue

log.processed = True
db.session.add(log)
db.session.commit()
Copy link
Member

Choose a reason for hiding this comment

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

We can reduce the number of database query per execution. Thoughts?

Suggested change
for log in failed_ivr_logs:
log.attempts += 1
db.session.add(log)
db.session.commit()
payload = json.loads(log.payload)
payload["log_created_on"] = log.created_on
processed = process_form_data(payload)
if processed is not True:
continue
log.processed = True
db.session.add(log)
db.session.commit()
for log in failed_ivr_logs:
payload = json.loads(log.payload)
payload["log_created_on"] = log.created_on
log.processed = process_form_data(payload)
log.attempts += 1
db.session.add(log)
db.session.commit()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this way, if the logic is not updating the status?

Copy link
Member

Choose a reason for hiding this comment

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

Yea, the log.processed should be either True or False. And if you seeprocess_form_data(payload), it returns a boolean value. So the status will be based on the return type. Do you think this doesn't work?

@GauravGusain98 GauravGusain98 merged commit 89d0611 into develop Dec 3, 2021
@GauravGusain98 GauravGusain98 deleted the feature/174-script-to-retry-failed-webhook branch December 3, 2021 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants