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

Switch over #29601

Draft
wants to merge 6 commits into
base: nh/rep/commands
Choose a base branch
from
Draft

Switch over #29601

wants to merge 6 commits into from

Conversation

kaapstorm
Copy link
Contributor

Summary

Repeat Records Couch-to-SQL migration PR 6 of 6

  • CEP
  • Note the base branch is that of the previous PR

See PR #29599 for more context.

The work I intended for this branch is not complete. You will notice "--wip--" commits at the end. I left myself a note to write the following tests to check that we don't create duplicate repeat records waiting to be sent:

  • Test register() drops payload if pending
  • Test register() drops payload if failed
  • Test register() drops payload if failed max times

Safety Assurance

  • Risk label is set correctly
  • All migrations are backwards compatible and won't block deploy
  • The set of people pinged as reviewers is appropriate for the level of risk of the change
  • If QA is part of the safety story, the "Awaiting QA" label is used
  • I have confidence that this PR will not introduce a regression for the reasons below

Automated test coverage

Test coverage for this PR is not complete.

QA Plan

Left to the discretion of the SaaS team.

Safety story

This PR will be subject to change. It is not safe to merge.

Rollback instructions

  • This PR can be reverted after deploy with no further considerations

False^^^. PR #29600 includes documentation and a management command to be used if this PR needs to be reverted. But those should be moot, because the way this Couch-to-SQL migration is to be deployed will change.

@kaapstorm kaapstorm added product/invisible Change has no end-user visible impact Risk: High Change affects files that have been flagged as high risk. labels Apr 23, 2021
@dimagimon dimagimon removed the Risk: High Change affects files that have been flagged as high risk. label Apr 23, 2021
get_repeaters_by_domain,
iter_repeat_records_by_repeater,
)
from ...models import Repeater, RepeaterStub

Choose a reason for hiding this comment

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

F401 '...models.RepeaterStub' imported but unused

Copy link
Contributor

@mjriley mjriley left a comment

Choose a reason for hiding this comment

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

Looks good, but I didn't fully grasp what was going on. I definitely skimmed over the tests


# Functions for evaluating scale
def get_repeat_record_domain_total():
from corehq.motech.repeaters.dbaccessors import get_domains_that_have_repeat_records
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 need this import? get_domains_that_have_repeat_records is in this same module



def get_couch_repeater_total():
from corehq.motech.repeaters.dbaccessors import get_domains_that_have_repeat_records
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as previous -- this import should be unnecessary



def get_couch_repeat_record_total():
from corehq.motech.repeaters.dbaccessors import get_domains_that_have_repeat_records
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as previous -- this import should be unnecessary


def get_couch_repeater_total():
from corehq.motech.repeaters.dbaccessors import get_domains_that_have_repeat_records
from corehq.motech.repeaters.models import Repeater
Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming this isn't a circular import, can this be moved to to the top of the file?

repeater.get_id):
if couch_record.migrated:
continue
migrate_repeat_record.delay(repeater.repeater_stub, couch_record)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is delay being used here as a form of multi-threading?

@@ -0,0 +1,42 @@
from inspect import cleandoc
Copy link
Contributor

Choose a reason for hiding this comment

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

This command (migrating couch repeater records to SQL) will have no use once migration is complete, right? Would a one-off script make more sense for this? I'd rather not create another command users need to ignore in ./manage.py (and I'd imagine it is a slight performance hit every time ./manage.py is executed)

Copy link
Contributor

Choose a reason for hiding this comment

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

We usually end up checking scripts like this in if only because they also need to be run by third parties that host HQ. We can delete them after we're reasonably confident everyone should have run them.

This comment reminded me, @kaapstorm how will the migration experience be for third parties? Will this command be integrated into a django migration like in the auto-managed pattern? Apologies if you've already discussed this - I'm quite late to the party, haven't been paying close attention to this migration recently.

Copy link
Contributor

Choose a reason for hiding this comment

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

(@kaapstorm ignore this question, I'm going to go read the doc about the repeaters migration plan)

# Payload is already waiting to be sent
return

self.repeater_stub.repeat_records.create(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the model already exists for this specific PR, but if it's within scope, I'll advocate for renaming RepeaterStub, as Stub already has a well-defined meaning within testing.

except: # noqa: E722
logging.exception('Failed to migrate repeat record: '
f'{couch_record.record_id}')
sql_record.delete()
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if this delete also fails? Do we have any logging in that circumstance?

@kaapstorm kaapstorm mentioned this pull request Jul 26, 2021
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product/invisible Change has no end-user visible impact
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants