<commit_before>from datetime import timedelta, date
from celery.task import periodic_task
from corehq.apps.domainsync.management.commands.copy_domain import Command
from .models import BackupRecord

import settings

GUINEA_CONTACT_TRACING_DOMAIN = 'guinea_contact_tracing'
GUINEA_CONTACT_TRACING_DATABASE = 'guineact-backup'


@periodic_task(run_every=timedelta(days=7), queue=settings.CELERY_PERIODIC_QUEUE)
def copy_data_to_backup():
    # https://<your_username>:<your_password>@comm<EMAIL>hq.cloudant.com/commcarehq
    prod_couchdb_connection = 'https://{username}:{password}@comm<EMAIL>hq.cloudant.com/{database}'.format(
        username=settings.COUCH_USERNAME,
        password=<PASSWORD>,
        database=settings.COUCH_DATABASE_NAME,
    )
    guinea_couchdb_connection = 'https://{username}:{password}@comm<EMAIL>hq.cloudant.com/{database}'.format(
        username=settings.COUCH_USERNAME,
        password=<PASSWORD>,
        database=GUINEA_CONTACT_TRACING_DATABASE,
    )
    last_update = BackupRecord.objects.order_by('last_update')[0]

    args = [
        prod_couchdb_connection,
        GUINEA_CONTACT_TRACING_DOMAIN,
        guinea_couchdb_connection
    ]
    kwargs = {
        'since': last_update,
    }
    Command.handle(args=args, kwargs=kwargs)

    successful_insert = BackupRecord(last_update=date.now())
    successful_insert.save()<commit_msg>Switch to call command, add soft assert email<commit_after>from datetime import timedelta, date
from celery.task import periodic_task
from django.core.management import call_command
from corehq.util.soft_assert import soft_assert
from .models import BackupRecord

import settings

GUINEA_CONTACT_TRACING_DOMAIN = 'guinea_contact_tracing'
GUINEA_CONTACT_TRACING_DATABASE = 'guineact-backup'


@periodic_task(run_every=timedelta(days=7), queue=settings.CELERY_PERIODIC_QUEUE)
def copy_data_to_backup():
    # https://<your_username>:<your_password>@commcarehq.cloudant.com/commcarehq
    prod_couchdb_connection = 'https://{username}:{password}@commcarehq.cloudant.com/{database}'.format(
        username=settings.COUCH_USERNAME,
        password=settings.COUCH_PASSWORD,
        database=settings.COUCH_DATABASE_NAME,
    )
    guinea_couchdb_connection = 'https://{username}:{password}@commcarehq.cloudant.com/{database}'.format(
        username=settings.COUCH_USERNAME,
        password=settings.COUCH_PASSWORD,
        database=GUINEA_CONTACT_TRACING_DATABASE,
    )
    last_update = BackupRecord.objects.order_by('last_update')[0]

    call_command('copy_domain',
                 prod_couchdb_connection,
                 GUINEA_CONTACT_TRACING_DOMAIN,
                 guinea_couchdb_connection,
                 **{'since': last_update})

    # A dumb soft assert to make sure I see this working
    _assert = soft_assert(to='{}<EMAIL>('<EMAIL>', 'dim<EMAIL>'), notify_admins=False, exponential_backoff=False)
    _assert(False)

    successful_insert = BackupRecord(last_update=date.now())
    successful_insert.save()
{'fraction_non_alphanumeric': 0.10242766877286331, 'fraction_numerical': 0.0013302294645826404, 'mean_word_length': 4.6647834274952915, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6485357', 'n_tokens_mistral': 1016, 'n_tokens_neox': 1005, 'n_words': 128}