from django.http import HttpRequest

from celery import task
from celery.task.schedules import crontab
from celery.decorators import periodic_task

__author__ = 'apredoi'

#from django_cron import cronScheduler, Job
from status_cron.views import *
from main.models import Module
#
#class CheckPassiveHosts(Job):
#    run_every = 60 #seconds
#
#    def job(self):
#        modules = Module.objects.filter(module_type='passive')
#        print "running check passive hosts cron"
#        for module in modules:
#            check_passive_hosts_task(HttpRequest(), module.id)

@periodic_task(run_every=crontab(hour="*", minute="*/1", day_of_week="*"))
def celery_task():
    modules = Module.objects.filter(module_type='passive')
    print "running check passive hosts cron"
    request = HttpRequest()
    request.META['HTTP_X_CELERY_CRON'] = 'true'
    for module in modules:
        check_passive_hosts_task.delay(request, module.id)


#class CheckNotifications(Job):
#    run_every = 120 #seconds
#
#
#    def job(self):
#        check_notifications(HttpRequest())

#cronScheduler.register(CheckPassiveHosts)
#cronScheduler.register(CheckNotifications)
@@ -651,18 +651,29 @@
 ef c
-elery_task
+heck_passive_monitors
 ():%0A
@@ -735,53 +735,9 @@
 e')%0A
-    print %22running check passive hosts cron%22
 %0A
+
     
@@ -808,16 +808,17 @@
  'true'%0A
+%0A
     for 
@@ -836,16 +836,16 @@
 odules:%0A
-
         
@@ -897,16 +897,396 @@
 e.id)%0A%0A%0A
+@periodic_task(run_every=crontab(hour=%22*%22, minute=%22*/5%22, day_of_week=%22*%22))%0Adef send_notifications():%0A    notifications = Notification.objects.filter(sent_at=None, send=True).order_by('-created_at')%0A%0A    request = HttpRequest()%0A    request.META%5B'HTTP_X_CELERY_CRON'%5D = 'true'%0A%0A    for notification in notifications:%0A        send_notification_task.delay(request, notification.id)%0A%0A%0A
 #class C

send notifications as celery cron as well