Commit efab9932 by Bach Dániel

SendMailTask: random fixes v2

parent d30ac29c
...@@ -213,6 +213,7 @@ firewall_settings = { ...@@ -213,6 +213,7 @@ firewall_settings = {
} }
EMAIL_HOST='cronos.ik.bme.hu' EMAIL_HOST='cronos.ik.bme.hu'
CLOUD_URL='https://cloud.ik.bme.hu/'
try: try:
from cloud.local_settings import * from cloud.local_settings import *
......
...@@ -6,6 +6,8 @@ from one.models import Instance ...@@ -6,6 +6,8 @@ from one.models import Instance
from django.template.loader import render_to_string from django.template.loader import render_to_string
from one.tasks import SendMailTask from one.tasks import SendMailTask
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from cloud.settings import CLOUD_URL as url
class Job(HourlyJob): class Job(HourlyJob):
help = "Suspend/delete expired Instances." help = "Suspend/delete expired Instances."
...@@ -20,7 +22,7 @@ class Job(HourlyJob): ...@@ -20,7 +22,7 @@ class Job(HourlyJob):
'2w': self.calc(orig=now, days=14), '2w': self.calc(orig=now, days=14),
'1w': self.calc(orig=now, days=7), '1w': self.calc(orig=now, days=7),
'1d': self.calc(orig=now, days=1), '1d': self.calc(orig=now, days=1),
'1h': self.calc(orig=now, hours=2), '1h': self.calc(orig=now, hours=1),
} }
# for i in d: # for i in d:
# print i+':'+unicode(d[i]) # print i+':'+unicode(d[i])
...@@ -29,13 +31,13 @@ class Job(HourlyJob): ...@@ -29,13 +31,13 @@ class Job(HourlyJob):
for i in Instance.objects.filter(state__in=['ACTIVE', 'STOPPED'], time_of_delete__isnull=False): for i in Instance.objects.filter(state__in=['ACTIVE', 'STOPPED'], time_of_delete__isnull=False):
print "%s delete: %s" % (i.name, i.time_of_delete) print "%s delete: %s" % (i.name, i.time_of_delete)
delete = i.time_of_delete.replace(minute=0, second=0, microsecond=0) delete = i.time_of_delete.replace(minute=0, second=0, microsecond=0)
if delete < now: if i.time_of_delete < now:
msg = render_to_string('mails/notification-delete-now.txt', { 'user': i.owner, 'instance': i } ) msg = render_to_string('mails/notification-delete-now.txt', { 'user': i.owner, 'instance': i, 'url': url } )
SendMailTask.delay(to=i.owner.email, subject='[IK Cloud] %s' % i.name, msg=msg) SendMailTask.delay(to=i.owner.email, subject='[IK Cloud] %s' % i.name, msg=msg)
else: else:
for t in d: for t in d:
if delete == d[t]: if delete == d[t]:
msg = render_to_string('mails/notification-delete.txt', { 'user': i.owner, 'instance': i } ) msg = render_to_string('mails/notification-delete.txt', { 'user': i.owner, 'instance': i, 'url': url } )
SendMailTask.delay(to=i.owner.email, subject='[IK Cloud] %s' % i.name, msg=msg) SendMailTask.delay(to=i.owner.email, subject='[IK Cloud] %s' % i.name, msg=msg)
# suspend # suspend
...@@ -43,12 +45,12 @@ class Job(HourlyJob): ...@@ -43,12 +45,12 @@ class Job(HourlyJob):
print "%s suspend: %s" % (i.name, i.time_of_suspend) print "%s suspend: %s" % (i.name, i.time_of_suspend)
suspend = i.time_of_suspend.replace(minute=0, second=0, microsecond=0) suspend = i.time_of_suspend.replace(minute=0, second=0, microsecond=0)
if suspend < now: if i.time_of_suspend < now:
msg = render_to_string('mails/notification-suspend-now.txt', { 'user': i.owner, 'instance': i } ) msg = render_to_string('mails/notification-suspend-now.txt', { 'user': i.owner, 'instance': i, 'url': url } )
SendMailTask.delay(to=i.owner.email, subject='[IK Cloud] %s' % i.name, msg=msg) SendMailTask.delay(to=i.owner.email, subject='[IK Cloud] %s' % i.name, msg=msg)
i.stop() i.stop()
else: else:
for t in d: for t in d:
if suspend == d[t]: if suspend == d[t]:
msg = render_to_string('mails/notification-suspend.txt', { 'user': i.owner, 'instance': i } ) msg = render_to_string('mails/notification-suspend.txt', { 'user': i.owner, 'instance': i, 'url': url } )
SendMailTask.delay(to=i.owner.email, subject='[IK Cloud] %s' % i.name, msg=msg) SendMailTask.delay(to=i.owner.email, subject='[IK Cloud] %s' % i.name, msg=msg)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment