-
Notifications
You must be signed in to change notification settings - Fork 5
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
#704 check purchase #709
#704 check purchase #709
Changes from 7 commits
7f0f608
2a6be11
99b1789
7b0b7a0
761364a
ab94fa8
f4896c8
01e4e95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.conf import settings | ||
from telegram import Bot | ||
|
||
|
||
class TelegramReport: | ||
|
||
def __init__(self): | ||
self.bot = Bot(settings.TG_BOT_TOKEN) | ||
|
||
def send(self, text: str): | ||
for id in settings.TG_REPORT_ADDRESSEES: | ||
self.bot.send_message(id, text) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
from .category import CategoryPage | ||
from .order import OrderPage | ||
from .success import SuccesPage |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from shopelectro.selenium.pages import Page | ||
|
||
from pages.models import CustomPage | ||
|
||
|
||
class SuccesPage(Page): | ||
|
||
@property | ||
def path(self): | ||
CustomPage.objects.get(slug='order-success').url | ||
|
||
def is_success(self): | ||
return 'Заказ принят' in self.driver.find_element_by_tag_name('h1').text |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,11 @@ | |
|
||
from django.conf import settings | ||
from django.core.management import call_command | ||
from selenium.common.exceptions import WebDriverException | ||
|
||
from shopelectro import selenium | ||
from shopelectro.celery import app | ||
from shopelectro.report import TelegramReport | ||
from shopelectro.models import CategoryPage | ||
from shopelectro.management.commands._update_catalog import utils | ||
|
||
|
@@ -61,18 +63,31 @@ def update_catalog(): | |
collect_static() | ||
] | ||
|
||
# @todo #690:60m Handle errors in check_purchase. | ||
# Report failed attempts. Schedule it in the celery beat. | ||
# @todo #690:30m Schedule check_purchase in the celery beat. | ||
|
||
|
||
@app.task | ||
def check_purchase(): | ||
driver = selenium.SiteDriver(site_url=settings.BASE_URL) | ||
category_page = selenium.CategoryPage(driver, CategoryPage.objects.first().url) | ||
category_page.load() | ||
category_page.add_to_cart() | ||
|
||
order_page = selenium.OrderPage(driver) | ||
order_page.load() | ||
order_page.fill_contacts() | ||
order_page.make_order() | ||
@app.task( | ||
bind=True, | ||
autoretry_for=(WebDriverException, AssertionError), | ||
retry_kwargs={'max_retries': settings.CHECK_PURCHASE_RETRIES}, | ||
) | ||
def check_purchase(self): | ||
try: | ||
driver = selenium.SiteDriver(site_url=settings.BASE_URL) | ||
category_page = selenium.CategoryPage(driver, CategoryPage.objects.first().url) | ||
category_page.load() | ||
category_page.add_to_cart() | ||
|
||
order_page = selenium.OrderPage(driver) | ||
order_page.load() | ||
order_page.fill_contacts() | ||
order_page.make_order() | ||
|
||
success_page = selenium.SuccessPage(driver) | ||
success_page.load() | ||
assert success_page.is_success() | ||
except (WebDriverException, AssertionError) as err: | ||
if self.request.retries + 1 > self.max_retries: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one failed retry seems to me enough reason to send the report. Why you choose three ones? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
but what if it is just false positive temporary issue, that usually occurs.
It's not, it will only send the message on the last attempt. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @artemiy312 , but this last attempt occurs every
it's not good, that it occurs. Tests on CI works fine. You can create setting var of course. But this problem requires more systematic decision There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @duker33 ,
i don't see the point. Can you describe it in more detail?
Let's just set max retries number to 1 and if there are issues with this, we will find a solution There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@artemiy312 , y, it's perfect. About |
||
# report on the last attempt | ||
TelegramReport().send(f'Can\'t buy a product. Got the error: {err}') | ||
raise err |
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.
@artemiy312 , i already suggested asyncio instead of celery beat at the parent issue's PR:
#695 (comment)
What do you think about it?
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.
I believe it is bad idea:
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 can move into rq, huye or something else, but it seems it will be the same picture
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.
i'll answer just for history: