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

feat: backpopulate transaction email and content title #181

Merged
merged 1 commit into from
Nov 21, 2023

Conversation

johnnagro
Copy link
Contributor

Description

Comment on lines 24 to 26
csod_only_filter = Q(integrated_channel_code='CSOD')
for items_batch in batch_by_pk(ContentMetadataItemTransmission, extra_filter=csod_only_filter):
for item in items_batch:
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: can we use more generic example model names, or make them not specific to integrated channels in here?


def generate_transaction_reversal_idempotency_key(fulfillment_uuid, enrollment_unenrolled_at):
"""
Generates a unique idempotency key for a transaction reversal using the fulfillment uuid and time at which the
unenrollment occurred.
"""
return f'unenrollment-reversal-{fulfillment_uuid}-{enrollment_unenrolled_at}'


def batch_by_pk(ModelClass, extra_filter=Q(), batch_size=10000):
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉 🎆

Comment on lines 58 to 59
lms_user_email = subsidy.email_for_learner(item.lms_user_id)
content_title = subsidy.title_for_content(item.content_key)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe only fetch these if the field is null - you can theoretically have records here where one of the two fields is non-null.

Comment on lines +31 to +40
parser.add_argument(
'--dry-run',
action='store_true',
dest='dry_run',
help=(
'If set, no updates will occur; will instead log '
'the actions that would have been taken.'
),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider whether we want to optionally skip internal-only subsidies (or maybe skip those by default).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tell me more?

Copy link
Contributor

Choose a reason for hiding this comment

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

We might have test subsidy records for say, performance testing, where there's lots and lots of test transaction records. We might want the ability to have this command ignore test subsidy records, so we don't have to wait on those being updated.

logger.info("Running in dry-run mode. No updates will occur.")

incomplete_only_filter = Q(lms_user_email__isnull=True) | Q(content_title__isnull=True)
for items_batch in batch_by_pk(Transaction, extra_filter=incomplete_only_filter):
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: batch_by_pk is really cool. OTOH, you could loop over Subsidies first to do some level of batching for you, and then the sequence of work would have some level of predictability, and you'd only need to fetch each subsidy record once. It also opens the door for us to do bulk fetches (filtered by the related subsidy record's enterprise uuid) in the future.

logger.info(f"Processing {subsidy.uuid} transaction {txn.uuid}")

if txn.lms_user_email is None:
lms_user_email = subsidy.email_for_learner(txn.lms_user_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to make these calls if self.dry_run is true? I could go either way - on the one hand, it's nice to set --dry-run just to see what would be updated, and then have that happen relatively quickly. On the other hand, it's nice to know with a dry run if we're actually fetching the data we expect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think we wanna be able to see that these API calls work without actually saving the results

Comment on lines +74 to +93
for txns in batch_by_pk(Transaction, extra_filter=txn_filter):
for txn in txns:
self.process_transaction(subsidy, txn)
Copy link
Contributor

Choose a reason for hiding this comment

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

Love this refactoring

if txn.lms_user_email is None:
lms_user_email = subsidy.email_for_learner(txn.lms_user_id)
txn.lms_user_email = lms_user_email
logger.info(f"Found {lms_user_email} for transaction {txn.uuid}")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: log the subsidy uuid in these logs, too

@johnnagro johnnagro force-pushed the johnnagro/ENT-7974/0 branch from 7d76db4 to c0e6240 Compare November 21, 2023 15:27
@johnnagro johnnagro merged commit 23e712f into main Nov 21, 2023
6 of 7 checks passed
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.

2 participants