Esempio n. 1
0
    def handle(self, id_start=0, id_end=1000000000000, *args, **options):
        id_start, id_end = int(id_start), int(id_end)
        last = time.time()
        n = 0

        err_count = 0
        for user in User.objects.filter(id__gte=id_start).exclude(id__gt=id_end).exclude(email='').order_by('id'):
            n += 1
            if n == BUCKET_BURSTS:
                n = 0
                while time.time() - last <= 1:
                    time.sleep(PAUSE)
                last = time.time()

            print "id: %s username: %r email: %r" % (user.id, user.username, user.email)
            try:
                fxn = Actions.newsletter
                # Bypass pushing it into bgwork
                fxn.__func__.do_not_deliver = True
                # Make a PendingNotification. Since we bypassed, it won't be expanded nor delivered.
                pn = fxn(user)
                expander.expand_and_deliver(pn)
            #TODO no catch-all exceptions!
            except Exception, e:
                import traceback; traceback.print_exc()
                err_count += 1
                if err_count >= 20:
                    raise
Esempio n. 2
0
 def action(cls, actor, *args, **kwargs):
     action_kwargs = dict(zip(arg_names, args))
     pending_notification = PendingNotification(actor, action_name, **action_kwargs)
     if not getattr(action, 'do_not_deliver', False):
         deliver = lambda: expander.expand_and_deliver(pending_notification)
         if kwargs.get('defer', True):
             defer(deliver)
         else:
             deliver()
     return pending_notification
Esempio n. 3
0
def send_welcome_email(user):
    """
    This doesn't protect against sending twice to the same user. You should call `recipients` and use its return
    value to get a fresh record of which users haven't received the email yet. This does save a record of which
    users were sent the email, but it doesn't check those records before sending - it's your responsibility to
    call `recipients` before calling this.
    """
    digest = Actions.digest
    do_not_deliver = getattr(digest, 'do_not_deliver', False)
    # Don't push it into bgwork.
    # See: http://stackoverflow.com/questions/7034063/adding-attributes-to-instancemethods-in-python
    digest.__func__.do_not_deliver = True

    pn = digest(user)

    # So that we don't send it twice to the same user.
    WelcomeEmailRecipient.objects.create(recipient=user)

    expander.expand_and_deliver(pn)

    digest.__func__.do_not_deliver = do_not_deliver
def send_welcome_email(user):
    """
    This doesn't protect against sending twice to the same user. You should call `recipients` and use its return
    value to get a fresh record of which users haven't received the email yet. This does save a record of which
    users were sent the email, but it doesn't check those records before sending - it's your responsibility to
    call `recipients` before calling this.
    """
    digest = Actions.digest
    do_not_deliver = getattr(digest, 'do_not_deliver', False)
    # Don't push it into bgwork.
    # See: http://stackoverflow.com/questions/7034063/adding-attributes-to-instancemethods-in-python
    digest.__func__.do_not_deliver = True

    pn = digest(user)

    # So that we don't send it twice to the same user.
    WelcomeEmailRecipient.objects.create(recipient=user)

    expander.expand_and_deliver(pn)

    digest.__func__.do_not_deliver = do_not_deliver
Esempio n. 5
0
 def action(cls, actor, *args, **kwargs):
     action_kwargs = dict(zip(arg_names, args))
     pending_notification = PendingNotification(actor, action_name,
                                                **action_kwargs)
     if not getattr(action, 'do_not_deliver', False):
         deliver = lambda: expander.expand_and_deliver(
             pending_notification)
         if kwargs.get('defer', True):
             defer(deliver)
         else:
             deliver()
     return pending_notification
Esempio n. 6
0
 def action(cls, actor, *args):
     kwargs = dict(zip(arg_names, args))
     pending_notification = PendingNotification(actor, action_name, **kwargs)
     if not getattr(action, 'do_not_deliver', False):
         defer(lambda: expander.expand_and_deliver(pending_notification))
     return pending_notification