commit 15d4014d24b7bcd710b4a3f61532a7483ee605ad
Author: Leonidas Poulopoulos <leopoul@noc.grnet.gr>
Date:   Tue Feb 14 12:16:06 2012 +0200

    Turned expiration notification cron job into celery job

diff --git a/cron_notify_expired.py b/cron_notify_expired.py
deleted file mode 100755
index 122625d..0000000
--- a/cron_notify_expired.py
+++ /dev/null
@@ -1,43 +0,0 @@
-from django.core.management import setup_environ  
-import settings
-setup_environ(settings)
-from django.core.mail import send_mail
-from flowspy.flowspec.models import *
-from django.template.loader import render_to_string
-from django.contrib.sites.models import Site
-from django.core.urlresolvers import reverse
-
-import datetime
-
-
-def notify_expired():
-    routes = Route.objects.all()
-    for route in routes:
-        if route.status not in ['EXPIRED', 'ADMININACTIVE', 'INACTIVE', 'ERROR']:
-            expiration_days = (route.expires - datetime.date.today()).days
-            if expiration_days < settings.EXPIRATION_NOTIFY_DAYS:
-                try:
-                    fqdn = Site.objects.get_current().domain
-                    admin_url = "https://%s%s" % \
-                    (fqdn,
-                     "/fod/edit/%s"%route.name)
-                    mail_body = render_to_string("rule_expiration.txt",
-                                             {"route": route, 'expiration_days':expiration_days, 'url':admin_url})
-                    days_num = ' days'
-                    expiration_days_text = "%s %s" %('in',expiration_days)
-                    if expiration_days == 0:
-                        days_num = ' today'
-                        expiration_days_text = ''
-                    if expiration_days == 1:
-                        days_num = ' day'
-                    send_mail(settings.EMAIL_SUBJECT_PREFIX + "Rule %s expires %s%s" %
-                              (route.name,expiration_days_text, days_num),
-                              mail_body, settings.SERVER_EMAIL,
-                              [route.applier.email])
-                except Exception as e:
-                    print e
-                    pass
-
-if __name__ == "__main__":
-    notify_expired()
-
diff --git a/flowspec/tasks.py b/flowspec/tasks.py
index 5f666ba..ad4853b 100644
--- a/flowspec/tasks.py
+++ b/flowspec/tasks.py
@@ -7,7 +7,12 @@ from celery.task.http import *
 import beanstalkc
 from django.conf import settings
 import datetime
-
+from flowspy.flowspec.models import *
+from django.core.mail import send_mail
+from flowspy.flowspec.models import *
+from django.template.loader import render_to_string
+from django.contrib.sites.models import Site
+from django.core.urlresolvers import reverse
 import os
 
 
@@ -132,6 +137,37 @@ def check_sync(route_name=None, selected_routes = []):
             if route.status != 'EXPIRED':
                 route.check_sync()
 
+@task(ignore_result=True)
+def notify_expired():
+    logger.info('Initializing expiration notification')
+    routes = Route.objects.all()
+    for route in routes:
+        if route.status not in ['EXPIRED', 'ADMININACTIVE', 'INACTIVE', 'ERROR']:
+            expiration_days = (route.expires - datetime.date.today()).days
+            if expiration_days < settings.EXPIRATION_NOTIFY_DAYS:
+                try:
+                    fqdn = Site.objects.get_current().domain
+                    admin_url = "https://%s%s" % \
+                    (fqdn,
+                     "/fod/edit/%s"%route.name)
+                    mail_body = render_to_string("rule_expiration.txt",
+                                             {"route": route, 'expiration_days':expiration_days, 'url':admin_url})
+                    days_num = ' days'
+                    expiration_days_text = "%s %s" %('in',expiration_days)
+                    if expiration_days == 0:
+                        days_num = ' today'
+                        expiration_days_text = ''
+                    if expiration_days == 1:
+                        days_num = ' day'
+                    logger.info('Route %s expires %s%s. Notifying %s (%s)' %(route.name, expiration_days_text, days_num, route.applier.username, route.applier.email))
+                    send_mail(settings.EMAIL_SUBJECT_PREFIX + "Rule %s expires %s%s" %
+                              (route.name,expiration_days_text, days_num),
+                              mail_body, settings.SERVER_EMAIL,
+                              [route.applier.email])
+                except Exception as e:
+                    logger.info("Exception: %s"%e)
+                    pass
+    logger.info('Expiration notification process finished')
 
 #def delete(route):
 #    
diff --git a/settings.py.dist b/settings.py.dist
index 1bfe6a2..e14b6ee 100644
--- a/settings.py.dist
+++ b/settings.py.dist
@@ -193,13 +193,17 @@ UI_USER_THEN_ACTIONS = ['discard', 'rate-limit']
 
 PROTECTED_SUBNETS = ['10.10.0.0/16']
 
-CELERYBEAT_SCHEDULE = {
-    # Executes every day at 01:35 AM 
+CELERYBEAT_SCHEDULE = { 
     "every-day-sync": {
         "task": "flowspec.tasks.check_sync",
         "schedule": crontab(minute=01, hour=01),
         "args": (),
     },
+    "notify-expired": {
+        "task": "flowspec.tasks.notify_expired",
+        "schedule": crontab(minute=01, hour=02),
+        "args": (),
+    },
 }
 # whois
 PRIMARY_WHOIS = 'whois.grnet.gr'
