コード例 #1
0
def send_summary_emails():
    stats.periodic_task('group__send_summary_emails')

    groups = Group.objects.annotate(member_count=Count('members')).filter(
        member_count__gt=0)
    for group in groups:

        from_date, to_date = emails.calculate_group_summary_dates(group)

        if not group.sent_summary_up_to or group.sent_summary_up_to < to_date:

            recipient_count = 0

            for email in emails.prepare_group_summary_emails(
                    group, from_date, to_date):
                try:
                    email.send()
                    recipient_count += len(email.to)
                except Exception:
                    traceback.print_exc()

            # we save this even if some of the email sending, no retries right now basically...
            group.sent_summary_up_to = to_date
            group.save()
            stats.group_summary_email(group, recipient_count)
コード例 #2
0
ファイル: tasks.py プロジェクト: oldPadavan/karrot-backend
def send_summary_emails():
    email_count = 0
    recipient_count = 0

    groups = Group.objects.annotate(member_count=Count('members')).filter(
        member_count__gt=0)

    for group in groups:

        from_date, to_date = emails.calculate_group_summary_dates(group)

        if not group.sent_summary_up_to or group.sent_summary_up_to < to_date:

            email_recipient_count = 0

            context = prepare_group_summary_data(group, from_date, to_date)
            if context['has_activity']:
                for email in emails.prepare_group_summary_emails(
                        group, context):
                    try:
                        email.send()
                        email_count += 1
                        email_recipient_count += len(email.to)
                    except AnymailAPIError:
                        sentry_client.captureException()

            # we save this even if some of the email sending fails, no retries right now basically...
            # we also save if no emails were sent due to missing activity, to not try again over and over.
            group.sent_summary_up_to = to_date
            group.save()

            stats.group_summary_email(
                group,
                email_recipient_count=email_recipient_count,
                feedback_count=context['feedbacks'].count(),
                message_count=context['messages'].count(),
                new_user_count=context['new_users'].count(),
                pickups_done_count=context['pickups_done_count'],
                pickups_missed_count=context['pickups_missed_count'],
                has_activity=context['has_activity'],
            )

            recipient_count += email_recipient_count

    stats_utils.periodic_task('group__send_summary_emails', {
        'recipient_count': recipient_count,
        'email_count': email_count,
    })
コード例 #3
0
ファイル: tasks.py プロジェクト: khatryshikha/karrot-backend
def send_summary_emails():
    email_count = 0
    recipient_count = 0

    groups = Group.objects.annotate(member_count=Count('members')).filter(
        member_count__gt=0)

    for group in groups:

        from_date, to_date = emails.calculate_group_summary_dates(group)

        if not group.sent_summary_up_to or group.sent_summary_up_to < to_date:

            email_recipient_count = 0

            context = prepare_group_summary_data(group, from_date, to_date)
            for email in emails.prepare_group_summary_emails(group, context):
                try:
                    email.send()
                    email_count += 1
                    email_recipient_count += len(email.to)
                except Exception:
                    traceback.print_exc()

            # we save this even if some of the email sending, no retries right now basically...
            group.sent_summary_up_to = to_date
            group.save()

            stats.group_summary_email(
                group,
                email_recipient_count=email_recipient_count,
                feedback_count=context['feedbacks'].count(),
                message_count=context['messages'].count(),
                new_user_count=context['new_users'].count(),
                pickups_done_count=context['pickups_done_count'],
                pickups_missed_count=context['pickups_missed_count'],
            )

            recipient_count += email_recipient_count

    stats_utils.periodic_task('group__send_summary_emails', {
        'recipient_count': recipient_count,
        'email_count': email_count,
    })