added simple task handling to handle_call() method; renamed email task to mail because of some name collision in smtplib

This commit is contained in:
Johannes Findeisen 2013-09-19 19:32:10 +02:00
commit bae0e3abce

View file

@ -11,17 +11,14 @@ from lib.tasks.task import Task
class EmailTask(Task): class EmailTask(Task):
def __init__(self, **kwargs): def __init__(self, **kwargs):
pass
'''
if not "type" in kwargs: if not "type" in kwargs:
raise Exception("'type' not in typeDict " + str(kwargs)) raise Exception("'type' not in typeDict " + str(kwargs))
if not "args" in kwargs: if not "args" in kwargs:
raise Exception("typeDict " + str(kwargs) + " has nor arguments!") raise Exception("typeDict " + str(kwargs) + " has nor arguments!")
self.set_task_type(kwargs["type"]) self.set_task_type(kwargs["type"])
self.recipient = kwargs["args"]["rcpt"] self.recipient = kwargs["args"]["rcpt"]
'''
def execute_task(self, msg): def execute(self, msg):
''' '''
message = MIMEText(msg) message = MIMEText(msg)
message['Subject'] = 'Warning from Linspector' message['Subject'] = 'Warning from Linspector'
@ -31,7 +28,12 @@ class EmailTask(Task):
s.sendmail("warning@linspector.org", self.recipient, message.as_string()) s.sendmail("warning@linspector.org", self.recipient, message.as_string())
s.quit() s.quit()
''' '''
print("Task executed")
print(msg)
print(self.recipient)
pass pass
def create(taskDict): def create(taskDict):
return EmailTask(**taskDict) return EmailTask(**taskDict)