Skip to content

Commit 24e450c

Browse files
authored
fix(worker): read payments from new payments.json + log full traceback (#67)
1 parent ab76fa0 commit 24e450c

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

src/tasks.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,17 @@ def read_analytics_file(package_status_id, package_id, link, session):
227227
'avatar_url': generate_avatar_url_from_user_id_avatar_hash(relation_ship['id'], relation_ship['user']['avatar']),
228228
'display_name': 'display_name' in relation_ship and relation_ship['display_name'] or None,
229229
})
230-
for payment in user_json['payments']:
230+
# Payments live at <user_root>/user_data_exports/discord_billing/payments.json
231+
# in current Discord exports. Skip silently if the file isn't there
232+
# (account never had any payment activity).
233+
payment_records = []
234+
user_root = user_path.rsplit('/', 1)[0]
235+
payments_path = f'{user_root}/user_data_exports/discord_billing/payments.json'
236+
if payments_path in zip.namelist():
237+
with zip.open(payments_path) as f:
238+
payment_records = orjson.loads(f.read()).get('records', [])
239+
240+
for payment in payment_records:
231241
payments.append({
232242
'id': payment['id'],
233243
'amount': payment['amount'],
@@ -928,13 +938,18 @@ def process_package(package_status_id, package_id, link, worker_name='regular_pr
928938
download_file(package_status_id, package_id, link, session)
929939
read_analytics_file(package_status_id, package_id, link, session)
930940
except Exception as e:
931-
print(e)
941+
# Always log the full trace to CloudWatch — print(e) alone gives just
942+
# the exception message and no line numbers, which makes the failure
943+
# impossible to debug from logs.
944+
tb = ''.join(traceback.format_exception(type(e), e, e.__traceback__))
945+
print(f'process_package failed for {package_id}:\n{tb}')
946+
932947
expected = ('EXPIRED_LINK')
933948
current = str(e)
934949
e_traceback = None
935950
if expected not in current:
936951
current = 'UNKNOWN_ERROR'
937-
e_traceback = ''.join(traceback.format_exception(type(e), e, e.__traceback__))
952+
e_traceback = tb
938953
session.query(PackageProcessStatus).filter(PackageProcessStatus.id == package_status_id).update({
939954
'is_errored': True,
940955
'error_message_code': current,

0 commit comments

Comments
 (0)