Skip to content

Commit

Permalink
Fix #806: reset retry and last_retry on resync command
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed Sep 15, 2023
1 parent b17799f commit 35f377c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ctms/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,17 @@ 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))
db.bulk_save_objects(
PendingAcousticRecord(email_id=email.email_id) for email in statement.all()
insert_stmt = insert(PendingAcousticRecord).values(
[{"email_id": email.email_id} for email in statement.all()]
)
insert_stmt = insert_stmt.on_conflict_do_update(
index_elements=[PendingAcousticRecord.email_id],
set_={
"retry": 0,
"last_error": "",
},
)
db.execute(insert_stmt)


def reset_retry_acoustic_records(db: Session):
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/bin/test_acoustic.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ 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, last_error="boom"
)
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
assert pending[0].last_error == ""


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
1 change: 1 addition & 0 deletions tests/unit/test_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def test_get_email_miss(dbsession):

def test_schedule_acoustic_record(dbsession, email_factory):
email = email_factory()
dbsession.commit()
schedule_acoustic_record(dbsession, email.email_id)
dbsession.commit()

Expand Down

0 comments on commit 35f377c

Please sign in to comment.