]> git.ozlabs.org Git - patchwork/blobdiff - patchwork/management/commands/cron.py
cron: Move patchwork-cron script to a management command
[patchwork] / patchwork / management / commands / cron.py
diff --git a/patchwork/management/commands/cron.py b/patchwork/management/commands/cron.py
new file mode 100755 (executable)
index 0000000..6217e75
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+
+from django.core.management.base import BaseCommand, CommandError
+from patchwork.utils import send_notifications, do_expiry
+
+class Command(BaseCommand):
+    help = ('Run periodic patchwork functions: send notifications and ' 
+            'expire unused users')
+
+    def handle(self, *args, **kwargs):
+        errors = send_notifications()
+        for (recipient, error) in errors:
+            self.stderr.write("Failed sending to %s: %s" %
+                                (recipient.email, ex))
+
+        do_expiry()
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv))
+