From cc8e07bc17aefcca2ae82b7b58c361c0365804cf Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Sun, 2 Aug 2015 17:42:49 +0300 Subject: [PATCH] added crone jobs --- SE_API/TaskRoutes.py | 45 ++++++++++++++++++++++---------------------- cron.yaml | 5 ++++- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index 0ef57e5..e7c6c54 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -25,6 +25,7 @@ from models.Project import Project #Validation Utils Libs from SE_API.Validation_Utils import * from SE_API.Respones_Utils import * +from Email_Utils import * task_routes = Blueprint("task_routes", __name__) @@ -871,30 +872,30 @@ def sendTaskReminder(): tasks = Task.all() - #go over all the courses - for t in tasks.run(): - if t.dueDate == datetime.date.today() + datetime.timedelta(days=1): - course = Course.get_by_id(int(t.courseId)) - if t.isPersonal: - for uId in course.membersId: - tc = TaskComponent.all().filter("taskId = ", t.key().id()).filter("userId = ", int(uId)) - if tc.count() == 0: - #SEND MAIL!! TODO - print "" + try: + for t in tasks.run(): + if t.dueDate == datetime.date.today() + datetime.timedelta(days=1): + course = Course.get_by_id(int(t.courseId)) + if t.isPersonal: + for uId in course.membersId: + tc = TaskComponent.all().filter("taskId = ", t.key().id()).filter("userId = ", int(uId)) + if tc.count() == 0: + user = User.get_by_id(int(uId)) + send_task_reminder(user.email, user.name, t.title, course.courseName) + print "" - else: - projects = Project.all().filter("courseId = ", course.key().id()) - for p in projects: - tc = TaskComponent.all().filter("taskId = ", t.key().id()).filter("userId = ", p.key().id()) - if tc.count() == 0: - #SEND MAIL!! TODO - print "" + else: + projects = Project.all().filter("courseId = ", course.key().id()) + for p in projects.run(): + tc = TaskComponent.all().filter("taskId = ", t.key().id()).filter("userId = ", p.key().id()) + if tc.count() == 0: + for uId in p.membersId: + user = User.get_by_id(int(uId)) + send_task_reminder(user.email, user.name, t.title, course.courseName) + return accepted() - - - #go over all - - return accepted("Task deleted") + except: + return bad_request() diff --git a/cron.yaml b/cron.yaml index 67b8d7e..d1ffbd4 100644 --- a/cron.yaml +++ b/cron.yaml @@ -1,4 +1,7 @@ cron: - description: update project data url: /api/projects/updateProjectsInfo - schedule: every 1 hours \ No newline at end of file + schedule: every 1 hours + - description: send task notification mail + url: /api/tasks/sendTaskReminder + schedule: every day 03:00 \ No newline at end of file