-
Notifications
You must be signed in to change notification settings - Fork 1
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 webhooks #215
#174 script to retry failed webhooks #215
Conversation
…lytics into feature/174-script-to-retry-failed-webhook
created_on=jsonData["log_created_on"] | ||
if jsonData.get("log_created_on", None) | ||
else datetime.now(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will only receive jsonData["log_created_on"]
for the retry logic.
def get_failed_webhook_transaction_log(self): | ||
failed_webhook_transaction_logs = ( | ||
models.WebhookTransactionLog.query.filter_by(processed=False) | ||
.limit(app.config["RETRY_LOGS_LIMIT"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
taking limit of the failed logs count using env
): | ||
handle_user_custom_field_data(jsonData) | ||
webhook_log = transaction_log_service.create_new_webhook_log(jsonData) | ||
processed = handle_payload(jsonData) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inside handle_payload function try and except are used for error handling and based on that it returns True or False
if "contact" in jsonData: | ||
transaction_log_service.mark_webhook_log_as_processed(webhook_log) | ||
elif jsonData and jsonData.get("type", None) == "retry_failed_log": | ||
retry_failed_webhook(transaction_log_service) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call retry login if we have "type": "retry_failed_log"
in json data.
for log in failed_webhook_logs: | ||
json_data = json.loads(log.payload) | ||
json_data["log_created_on"] = log.created_on | ||
processed = handle_payload(json_data, True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Processing all the failed logs. The second parameter is for differentiating regular webhooks and retry webhooks
db_helper.save(log) | ||
|
||
|
||
def handle_payload(jsonData, is_retry_payload=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initial logic for handling webhooks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one suggestion else looks good. Please fix and merge
config.py
Outdated
RETRY_LOGS_BATCH_LIMIT = os.environ.get("RETRY_LOGS_BATCH_LIMIT") | ||
MAX_RETRY_ATTEMPTS_FOR_LOGS = os.environ.get("MAX_RETRY_ATTEMPTS_FOR_LOGS") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a fallback value (kind of default value) like you must have seen frameworks config files?
#174
Please complete the following steps and check these boxes before filing your PR:
Types of changes
Short description of what this resolves:
Checklist: