setting up to automate daily campaign status update
parent
275d127e29
commit
5b733d214c
|
@ -237,7 +237,8 @@ class Campaign(models.Model):
|
|||
self.save()
|
||||
action = CampaignAction(campaign=self, type='failed', comment = self.current_total)
|
||||
action.save()
|
||||
regluit.core.signals.unsuccessful_campaign.send(sender=None,campaign=self)
|
||||
if send_notice:
|
||||
regluit.core.signals.unsuccessful_campaign.send(sender=None,campaign=self)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
|
|
@ -10,8 +10,13 @@ from django.contrib.auth.models import User
|
|||
|
||||
from regluit.core import bookloader, models
|
||||
from regluit.core import goodreads, librarything
|
||||
from regluit.core.models import Campaign
|
||||
from regluit.utils.localdatetime import now, date_today
|
||||
|
||||
from django.core.mail import send_mail
|
||||
|
||||
from notification.engine import send_all
|
||||
from notification import models as notification
|
||||
|
||||
@task
|
||||
def populate_edition(isbn):
|
||||
|
@ -51,23 +56,22 @@ def fac(n, sleep_interval=None):
|
|||
sleep(sleep_interval)
|
||||
return res
|
||||
|
||||
from django.core.mail import get_connection
|
||||
from django.core.mail.message import EmailMessage
|
||||
|
||||
@task
|
||||
def send_mail_task(subject, message, from_email, recipient_list,
|
||||
fail_silently=False, auth_user=None, auth_password=None,
|
||||
connection=None):
|
||||
"""a task to drop django.core.mail.send_mail into """
|
||||
connection = connection or get_connection(username=auth_user,
|
||||
password=auth_password,
|
||||
fail_silently=fail_silently)
|
||||
return EmailMessage(subject, message, from_email, recipient_list,
|
||||
connection=connection, headers = {'Reply-To': from_email }).send()
|
||||
|
||||
"""a task to drop django.core.mail.send_mail into """
|
||||
return send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=auth_user,
|
||||
auth_password=auth_password, connection=connection)
|
||||
|
||||
from notification.engine import send_all
|
||||
from notification import models as notification
|
||||
|
||||
#task to update the status of active campaigns
|
||||
|
||||
@task
|
||||
def update_active_campaign_status():
|
||||
"""update the status of all active campaigns -- presumed to be run at midnight Eastern time"""
|
||||
return [c.update_status(send_notice=True) for c in Campaign.objects.filter(status='Active') ]
|
||||
|
||||
@task
|
||||
def emit_notifications():
|
||||
|
|
|
@ -236,8 +236,14 @@ from celery.schedules import crontab
|
|||
|
||||
SEND_TEST_EMAIL_JOB = {
|
||||
"task": "regluit.core.tasks.send_mail_task",
|
||||
"schedule": datetime.timedelta(seconds=30),
|
||||
"args": ('hi there', 'testing 1, 2, 3', 'raymond.yee@gmail.com', ['raymond.yee@gmail.com'])
|
||||
"schedule": crontab(hour=18, minute=20),
|
||||
"args": ('hi there 18:20', 'testing 1, 2, 3', 'notices@gluejar.com', ['raymond.yee@gmail.com'])
|
||||
}
|
||||
|
||||
UPDATE_ACTIVE_CAMPAIGN_STATUSES = {
|
||||
"task": "regluit.core.tasks.update_active_campaign_status",
|
||||
"schedule": crontab(hour=18, minute=5),
|
||||
"args": ()
|
||||
}
|
||||
|
||||
EMIT_NOTIFICATIONS_JOB = {
|
||||
|
|
Loading…
Reference in New Issue