Ejemplo n.º 1
0
def process_fire_events(fire_ids):
    from temba.campaigns.models import EventFire

    # every event fire in the batch will be for the same flow... but if the flow has been deleted then fires won't exist
    single_fire = EventFire.objects.filter(id__in=fire_ids).first()
    if not single_fire:  # pragma: no cover
        return

    flow = single_fire.event.flow

    # lock on the flow so we know non-one else is updating these event fires
    r = get_redis_connection()
    with r.lock('process_fire_events:%d' % flow.id, timeout=300):

        # only fetch fires that haven't been somehow already handled
        fires = list(
            EventFire.objects.filter(id__in=fire_ids,
                                     fired=None).prefetch_related('contact'))
        if fires:
            print("E[%s][%s] Batch firing %d events..." %
                  (flow.org.name, flow.name, len(fires)))

            start = time.time()
            EventFire.batch_fire(fires, flow)

            print("E[%s][%s] Finished batch firing events in %.3f s" %
                  (flow.org.name, flow.name, time.time() - start))
Ejemplo n.º 2
0
def process_fire_events(fire_ids):
    from temba.campaigns.models import EventFire

    # every event fire in the batch will be for the same flow... but if the flow has been deleted then fires won't exist
    single_fire = EventFire.objects.filter(id__in=fire_ids).first()
    if not single_fire:  # pragma: no cover
        return

    flow = single_fire.event.flow

    # lock on the flow so we know non-one else is updating these event fires
    r = get_redis_connection()
    with r.lock("process_fire_events:%d" % flow.id, timeout=300):

        # only fetch fires that haven't been somehow already handled
        fires = list(EventFire.objects.filter(id__in=fire_ids, fired=None).prefetch_related("contact"))
        if fires:
            print("E[%s][%s] Batch firing %d events..." % (flow.org.name, flow.name, len(fires)))

            start = time.time()
            EventFire.batch_fire(fires, flow)

            print("E[%s][%s] Finished batch firing events in %.3f s" % (flow.org.name, flow.name, time.time() - start))