Skip to content

Commit

Permalink
Fix #806: reset retry and last_error columns on resync command
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed Sep 5, 2023
1 parent b089a61 commit 0e3fecf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ctms/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,14 @@ def get_all_acoustic_records_count(

def bulk_schedule_acoustic_records(db: Session, primary_emails: list[str]):
"""Mark a list of primary email as pending synchronization."""
statement = _contact_base_query(db).filter(Email.primary_email.in_(primary_emails))
email_ids = (
db.query(Email.email_id).filter(Email.primary_email.in_(primary_emails)).all()
)
db.query(PendingAcousticRecord).filter(
PendingAcousticRecord.email_id.in_(email_id for (email_id,) in email_ids)
).delete()
db.bulk_save_objects(
PendingAcousticRecord(email_id=email.email_id) for email in statement.all()
PendingAcousticRecord(email_id=email_id) for (email_id,) in email_ids
)


Expand Down
17 changes: 17 additions & 0 deletions tests/unit/bin/test_acoustic.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ def test_main_force_resync_by_email_list(dbsession, maximal_contact, tmpdir):
assert len(dbsession.query(PendingAcousticRecord).all()) > 0


def test_main_force_resync_will_reset_existing_retries(
dbsession, maximal_contact, tmpdir
):
record = PendingAcousticRecord(email_id=maximal_contact.email.email_id, retry=99)
dbsession.add(record)
dbsession.flush()

f = tmpdir.join("temp.txt")
f.write(maximal_contact.email.primary_email)
do_resync(dbsession, assume_yes=True, emails_file=f)
dbsession.flush()

pending = dbsession.query(PendingAcousticRecord).all()
assert len(pending) == 1
assert pending[0].retry == 0


def test_main_force_resync_by_reset_retry(dbsession, minimal_contact, maximal_contact):
record = PendingAcousticRecord(email_id=minimal_contact.email.email_id, retry=99)
dbsession.add(record)
Expand Down

0 comments on commit 0e3fecf

Please sign in to comment.