Exemplo n.º 1
0
def reprocess_archive_stubs():
    # Check for archive stubs
    from corehq.form_processor.interfaces.dbaccessors import FormAccessors
    from couchforms.models import UnfinishedArchiveStub
    stubs = UnfinishedArchiveStub.objects.filter(attempts__lt=3)
    datadog_gauge('commcare.unfinished_archive_stubs', len(stubs))
    start = time.time()
    cutoff = start + timedelta(minutes=4).total_seconds()
    for stub in stubs:
        # Exit this task after 4 minutes so that tasks remain short
        if time.time() > cutoff:
            return
        try:
            xform = FormAccessors(stub.domain).get_form(form_id=stub.xform_id)
            # If the history wasn't updated the first time around, run the whole thing again.
            if not stub.history_updated:
                FormAccessors.do_archive(xform,
                                         stub.archive,
                                         stub.user_id,
                                         trigger_signals=True)

            # If the history was updated the first time around, just send the update to kafka
            else:
                FormAccessors.publish_archive_action_to_kafka(
                    xform, stub.user_id, stub.archive)
        except Exception:
            # Errors should not prevent processing other stubs
            notify_exception(None, "Error processing UnfinishedArchiveStub")
Exemplo n.º 2
0
def reprocess_archive_stubs():
    # Check for archive stubs
    from corehq.form_processor.interfaces.dbaccessors import FormAccessors
    from couchforms.models import UnfinishedArchiveStub
    stubs = UnfinishedArchiveStub.objects.filter()
    datadog_gauge('commcare.unfinished_archive_stubs', len(stubs))
    start = time.time()
    cutoff = start + timedelta(minutes=4).total_seconds()
    for stub in stubs:
        # Exit this task after 4 minutes so that the same stub isn't ever processed in multiple queues.
        if time.time() - start > cutoff:
            return
        xform = FormAccessors(stub.domain).get_form(form_id=stub.xform_id)
        # If the history wasn't updated the first time around, run the whole thing again.
        if not stub.history_updated:
            if stub.archive:
                xform.archive(user_id=stub.user_id)
            else:
                xform.unarchive(user_id=stub.user_id)
        # If the history was updated the first time around, just send the update to kafka
        else:
            xform.publish_archive_action_to_kafka(user_id=stub.user_id, archive=stub.archive)
Exemplo n.º 3
0
def reprocess_archive_stubs():
    # Check for archive stubs
    from corehq.form_processor.interfaces.dbaccessors import FormAccessors
    from couchforms.models import UnfinishedArchiveStub
    stubs = UnfinishedArchiveStub.objects.filter()
    datadog_gauge('commcare.unfinished_archive_stubs', len(stubs))
    start = time.time()
    cutoff = start + timedelta(minutes=4).total_seconds()
    for stub in stubs:
        # Exit this task after 4 minutes so that the same stub isn't ever processed in multiple queues.
        if time.time() - start > cutoff:
            return
        xform = FormAccessors(stub.domain).get_form(form_id=stub.xform_id)
        # If the history wasn't updated the first time around, run the whole thing again.
        if not stub.history_updated:
            if stub.archive:
                xform.archive(user_id=stub.user_id)
            else:
                xform.unarchive(user_id=stub.user_id)
        # If the history was updated the first time around, just send the update to kafka
        else:
            xform.publish_archive_action_to_kafka(user_id=stub.user_id, archive=stub.archive)