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

Overhaul Adjustments + Bugfix #525

Merged
merged 2 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
16 changes: 8 additions & 8 deletions microsetta_private_api/celery_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ def __call__(self, *args, **kwargs):
"task": "microsetta_private_api.util.fundrazr.get_fundrazr_transactions", # noqa
"schedule": 60 * 60 # every hour
},
"fulfill_new_transactions": {
"task": "microsetta_private_api.util.perk_fulfillment.fulfill_new_transactions", # noqa
"schedule": 60 * 60 # every hour
},
# "fulfill_new_transactions": {
# "task": "microsetta_private_api.util.perk_fulfillment.fulfill_new_transactions", # noqa
# "schedule": 60 * 60 # every hour
# },
# "fulfill_subscriptions": {
# "task": "microsetta_private_api.util.perk_fulfillment.process_subscription_fulfillments", # noqa
# "schedule": 60 * 60 * 24 # every 24 hours
# },
# "check_shipping_updates": {
# "task": "microsetta_private_api.util.perk_fulfillment.check_shipping_updates", # noqa
# "schedule": 60 * 60 * 4 # every 4 hours
# },
"check_shipping_updates": {
"task": "microsetta_private_api.util.perk_fulfillment.check_shipping_updates", # noqa
"schedule": 60 * 60 * 4 # every 4 hours
},
# "perks_without_fulfillment_details": {
# "task": "microsetta_private_api.util.perk_fulfillment.perks_without_fulfillment_details", # noqa
# "schedule": 60 * 60 * 24 # every 24 hours
Expand Down
26 changes: 15 additions & 11 deletions microsetta_private_api/repo/perk_fulfillment_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ def process_pending_fulfillment(self, ftp_id):
# been processed and collect the necessary fields
cur.execute(
"SELECT ftp.id ftp_id, ftp.transaction_id, ftp.perk_id, "
"ftp.quantity, ft.payer_email, fpfd.ffq_quantity, "
"ftp.quantity, fpfd.ffq_quantity, "
"fpfd.kit_quantity, fpfd.dak_article_code, "
"fpfd.fulfillment_spacing_number, "
"fpfd.fulfillment_spacing_unit, iu.first_name, iu.last_name, "
"iu.phone, iu.address_1, iu.address_2, iu.city, iu.state, "
"iu.postal_code, iu.country, iu.campaign_id "
"iu.postal_code, iu.country, iu.campaign_id, iu.email "
"FROM campaign.fundrazr_transaction_perk ftp "
"INNER JOIN campaign.transaction ft "
"ON ftp.transaction_id = ft.id "
Expand All @@ -99,7 +99,7 @@ def process_pending_fulfillment(self, ftp_id):
if row is not None:
if self._is_subscription(row):
subscription_id = \
self._create_subscription(row['payer_email'],
self._create_subscription(row['email'],
row['transaction_id'],
row['ftp_id'])
else:
Expand All @@ -119,7 +119,7 @@ def process_pending_fulfillment(self, ftp_id):
error_info = self._fulfill_ffq(
row['ftp_id'],
template,
row['payer_email'],
row['email'],
row['first_name'],
subscription_id
)
Expand Down Expand Up @@ -148,7 +148,7 @@ def process_pending_fulfillment(self, ftp_id):
error_info = self._fulfill_ffq(
row['ftp_id'],
row['kit_quantity'],
row['payer_email'],
row['email'],
row['first_name']
)
if error_info is not None:
Expand Down Expand Up @@ -230,7 +230,7 @@ def process_subscription_fulfillment(self, fulfillment_id):
cur.execute(
"SELECT sf.fulfillment_id, sf.fulfillment_type, "
"sf.dak_article_code, sf.subscription_id, ftp.id ftp_id, "
"ft.payer_email, iu.first_name, iu.last_name, iu.phone, "
"iu.email iu_email, iu.first_name, iu.last_name, iu.phone, "
"iu.address_1, iu.address_2, iu.city, iu.state, "
"iu.postal_code, iu.country, iu.campaign_id, s.account_id, "
"a.email a_email, a.first_name a_first_name, "
Expand Down Expand Up @@ -265,7 +265,7 @@ def process_subscription_fulfillment(self, fulfillment_id):
first_name = row['a_first_name']
# If no account, fall back to original Fundrazr data
else:
email = row['payer_email']
email = row['iu_email']
first_name = row['first_name']

email_error = self._fulfill_ffq(
Expand Down Expand Up @@ -321,7 +321,7 @@ def check_for_shipping_updates(self):
cur.execute(
"SELECT fdo.fundrazr_transaction_perk_id ftp_id, "
"fdo.dak_order_id, kit.outbound_fedex_tracking, "
"t.payer_email, t.payer_first_name "
"iu.email, iu.first_name "
"FROM campaign.fundrazr_daklapack_orders fdo "
"INNER JOIN barcodes.daklapack_order dako "
"ON fdo.dak_order_id = dako.dak_order_id "
Expand All @@ -334,18 +334,20 @@ def check_for_shipping_updates(self):
"ON fdo.fundrazr_transaction_perk_id = ftp.id "
"INNER JOIN campaign.transaction t "
"ON ftp.transaction_id = t.id "
"INNER JOIN campaign.interested_users iu "
"ON t.interested_user_id = iu.interested_user_id "
"WHERE fdo.tracking_sent = false"
)
rows = cur.fetchall()
template = "kit_tracking_number"
for r in rows:
try:
email_args = {
"first_name": r['payer_first_name'],
"first_name": r['first_name'],
"tracking_number": r['outbound_fedex_tracking']
}

email_address = r['payer_email']
email_address = r['email']

send_email(
email_address,
Expand Down Expand Up @@ -663,7 +665,9 @@ def get_unclaimed_subscriptions_by_email(self, email):
"FROM campaign.subscriptions s "
"INNER JOIN campaign.transaction t "
"ON s.transaction_id = t.id "
"WHERE account_id IS NULL AND LOWER(t.payer_email) = %s",
"INNER JOIN campaign.interested_users iu "
"ON t.interested_user_id = iu.interested_user_id "
"WHERE account_id IS NULL AND LOWER(iu.email) = %s",
(email, )
)
rows = cur.fetchall()
Expand Down
2 changes: 1 addition & 1 deletion microsetta_private_api/repo/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Transaction:
# Note: SimpleConnectionPool works only for single threaded applications
# Should we make the server multi threaded, we must switch to a
Copy link
Member

Choose a reason for hiding this comment

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

:/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, I'll update that comment before I merge. Thanks for the quick review.

# ThreadedConnectionPool
_POOL = psycopg2.pool.SimpleConnectionPool(
_POOL = psycopg2.pool.ThreadedConnectionPool(
1,
20,
user=AMGUT_CONFIG.user,
Expand Down
2 changes: 2 additions & 0 deletions microsetta_private_api/util/perk_fulfillment.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def check_shipping_updates():
emails_sent, error_report = pfr.check_for_shipping_updates()

if emails_sent > 0 or len(error_report) > 0:
t.commit()

email_content = f"Emails sent: {emails_sent}\n"\
f"Errors: {error_report}"
try:
Expand Down