Esempio n. 1
0
 def test_crontab_hour(self):
     # validates the following hours
     valids = [0, 1, 4, 6, 8, 9, 12, 18]
     validate_h = crontab(hour='8-9,*/6,1,4')
     
     for x in xrange(24):
         res = validate_h(datetime.datetime(2011, 1, 1, x))
         self.assertEqual(res, x in valids)
     
     edge = crontab(hour=0)
     self.assertTrue(edge(datetime.datetime(2011, 1, 1, 0, 0)))
     self.assertFalse(edge(datetime.datetime(2011, 1, 1, 12, 0)))
Esempio n. 2
0
    def test_crontab_hour(self):
        # validates the following hours
        valids = [0, 1, 4, 6, 8, 9, 12, 18]
        validate_h = crontab(hour='8-9,*/6,1,4')

        for x in xrange(24):
            res = validate_h(datetime.datetime(2011, 1, 1, x))
            self.assertEqual(res, x in valids)

        edge = crontab(hour=0)
        self.assertTrue(edge(datetime.datetime(2011, 1, 1, 0, 0)))
        self.assertFalse(edge(datetime.datetime(2011, 1, 1, 12, 0)))
Esempio n. 3
0
 def test_crontab_all_together(self):
     # jan 1, 2011 is a saturday
     # may 1, 2011 is a sunday
     validate = crontab(
         month='1,5',
         day='1,4,7',
         day_of_week='0,6',
         hour='*/4',
         minute='1-5,10-15,50'
     )
     
     self.assertTrue(validate(datetime.datetime(2011, 5, 1, 4, 11)))
     self.assertTrue(validate(datetime.datetime(2011, 5, 7, 20, 50)))
     self.assertTrue(validate(datetime.datetime(2011, 1, 1, 0, 1)))
     
     # fails validation on month
     self.assertFalse(validate(datetime.datetime(2011, 6, 4, 4, 11)))
     
     # fails validation on day
     self.assertFalse(validate(datetime.datetime(2011, 1, 6, 4, 11)))
     
     # fails validation on day_of_week
     self.assertFalse(validate(datetime.datetime(2011, 1, 4, 4, 11)))
     
     # fails validation on hour
     self.assertFalse(validate(datetime.datetime(2011, 1, 1, 1, 11)))
     
     # fails validation on minute
     self.assertFalse(validate(datetime.datetime(2011, 1, 1, 4, 6)))
Esempio n. 4
0
    def test_crontab_all_together(self):
        # jan 1, 2011 is a saturday
        # may 1, 2011 is a sunday
        validate = crontab(month='1,5',
                           day='1,4,7',
                           day_of_week='0,6',
                           hour='*/4',
                           minute='1-5,10-15,50')

        self.assertTrue(validate(datetime.datetime(2011, 5, 1, 4, 11)))
        self.assertTrue(validate(datetime.datetime(2011, 5, 7, 20, 50)))
        self.assertTrue(validate(datetime.datetime(2011, 1, 1, 0, 1)))

        # fails validation on month
        self.assertFalse(validate(datetime.datetime(2011, 6, 4, 4, 11)))

        # fails validation on day
        self.assertFalse(validate(datetime.datetime(2011, 1, 6, 4, 11)))

        # fails validation on day_of_week
        self.assertFalse(validate(datetime.datetime(2011, 1, 4, 4, 11)))

        # fails validation on hour
        self.assertFalse(validate(datetime.datetime(2011, 1, 1, 1, 11)))

        # fails validation on minute
        self.assertFalse(validate(datetime.datetime(2011, 1, 1, 4, 6)))
Esempio n. 5
0
    def test_crontab_minute(self):
        # validates the following minutes
        valids = [0, 1, 4, 6, 8, 9, 12, 18, 24, 30, 36, 42, 48, 54]
        validate_m = crontab(minute='4,8-9,*/6,1')

        for x in xrange(60):
            res = validate_m(datetime.datetime(2011, 1, 1, 1, x))
            self.assertEqual(res, x in valids)
Esempio n. 6
0
    def test_crontab_day(self):
        # validates the following days
        valids = [1, 4, 7, 8, 9, 13, 19, 25, 31]
        validate_d = crontab(day='*/6,1,4,8-9')

        for x in xrange(1, 32):
            res = validate_d(datetime.datetime(2011, 1, x))
            self.assertEqual(res, x in valids)
Esempio n. 7
0
 def test_crontab_minute(self):
     # validates the following minutes
     valids = [0, 1, 4, 6, 8, 9, 12, 18, 24, 30, 36, 42, 48, 54]
     validate_m = crontab(minute='4,8-9,*/6,1')
     
     for x in xrange(60):
         res = validate_m(datetime.datetime(2011, 1, 1, 1, x))
         self.assertEqual(res, x in valids)
Esempio n. 8
0
 def test_crontab_day(self):
     # validates the following days
     valids = [1, 4, 7, 8, 9, 13, 19, 25, 31]
     validate_d = crontab(day='*/6,1,4,8-9')
     
     for x in xrange(1, 32):
         res = validate_d(datetime.datetime(2011, 1, x))
         self.assertEqual(res, x in valids)
Esempio n. 9
0
 def test_crontab_month(self):
     # validates the following months, 1, 4, 7, 8, 9
     valids = [1, 4, 7, 8, 9]
     validate_m = crontab(month='1,4,*/6,8-9')
     
     for x in xrange(1, 13):
         res = validate_m(datetime.datetime(2011, x, 1))
         self.assertEqual(res, x in valids)
Esempio n. 10
0
    def test_crontab_month(self):
        # validates the following months, 1, 4, 7, 8, 9
        valids = [1, 4, 7, 8, 9]
        validate_m = crontab(month='1,4,*/6,8-9')

        for x in xrange(1, 13):
            res = validate_m(datetime.datetime(2011, x, 1))
            self.assertEqual(res, x in valids)
Esempio n. 11
0
    def test_crontab_day_of_week(self):
        # validates the following days of week
        # jan, 1, 2011 is a saturday
        valids = [2, 4, 9, 11, 16, 18, 23, 25, 30]
        validate_dow = crontab(day_of_week='0,2')

        for x in xrange(1, 32):
            res = validate_dow(datetime.datetime(2011, 1, x))
            self.assertEqual(res, x in valids)
Esempio n. 12
0
 def test_crontab_day_of_week(self):
     # validates the following days of week
     # jan, 1, 2011 is a saturday
     valids = [2, 4, 9, 11, 16, 18, 23, 25, 30]
     validate_dow = crontab(day_of_week='0,2')
     
     for x in xrange(1, 32):
         res = validate_dow(datetime.datetime(2011, 1, x))
         self.assertEqual(res, x in valids)
Esempio n. 13
0
    def test_crontab_all_together(self):
        # jan 1, 2011 is a saturday
        # may 1, 2011 is a sunday
        validate = crontab(month="1,5", day="1,4,7", day_of_week="0,6", hour="*/4", minute="1-5,10-15,50")

        self.assertTrue(validate(datetime.datetime(2011, 5, 1, 4, 11)))
        self.assertTrue(validate(datetime.datetime(2011, 5, 7, 20, 50)))
        self.assertTrue(validate(datetime.datetime(2011, 1, 1, 0, 1)))

        # fails validation on month
        self.assertFalse(validate(datetime.datetime(2011, 6, 4, 4, 11)))

        # fails validation on day
        self.assertFalse(validate(datetime.datetime(2011, 1, 6, 4, 11)))

        # fails validation on day_of_week
        self.assertFalse(validate(datetime.datetime(2011, 1, 4, 4, 11)))

        # fails validation on hour
        self.assertFalse(validate(datetime.datetime(2011, 1, 1, 1, 11)))

        # fails validation on minute
        self.assertFalse(validate(datetime.datetime(2011, 1, 1, 4, 6)))
Esempio n. 14
0
import datetime

from django.conf import settings
from django.db import connection

from djutils import dashboard
from djutils.dashboard.models import Panel, PanelData, PanelDataSet, PANEL_AGGREGATE_MINUTE
from djutils.queue.decorators import periodic_command, crontab

dashboard.autodiscover()

# set to 0 or None to prevent data from expiring
EXPIRATION_DAYS = getattr(settings, 'PANEL_DATA_EXPIRATION_DAYS', 7)

@periodic_command(crontab())
def update_panels():
    """
    Simple task which updates the dashboard panels every minute
    """
    Panel.objects.update_panels()

@periodic_command(crontab(minute=0, hour='*'))
def generate_hourly_aggregates():
    Panel.objects.generate_hourly_aggregates()

@periodic_command(crontab(minute=0, hour=0))
def generate_daily_aggregates():
    Panel.objects.generate_daily_aggregates()

@periodic_command(crontab(minute=0, hour=0))
def remove_old_panel_data():
Esempio n. 15
0
from django.conf import settings
from django.core.mail import mail_admins
from django.template.loader import render_to_string

from spider.models import SpiderSession, SpiderProfile

from djutils.queue.decorators import queue_command, periodic_command, crontab


# by default do not send emails
EMAIL_STATUS_CHECK = getattr(settings, 'SPIDER_EMAIL_STATUS_CHECK', False) 

@periodic_command(crontab(minute='*/30'))
def check_health():
    errors = []
    for profile in SpiderProfile.objects.all():
        status_check = profile.check_health()
        if not status_check.is_ok():
            errors.append(status_check)
    
    if errors and EMAIL_STATUS_CHECK:
        message = render_to_string('spider/email/status_check.txt', {
            'status_check_list': errors
        })
        mail_admins('Spider status check error email', message.strip(), fail_silently=True)

@queue_command
def run_spider(session_id):
    session = SpiderSession.objects.get(pk=session_id)
    session.spider()
Esempio n. 16
0
 def validate_datetime(self, dt):
     return crontab(minute='*/30')(dt)
Esempio n. 17
0
 def validate_datetime(self, dt):
     return crontab(minute='*/30')(dt)
Esempio n. 18
0
from django.conf import settings
from django.core.mail import mail_admins
from django.template.loader import render_to_string

from spider.models import SpiderSession, SpiderProfile

from djutils.queue.decorators import queue_command, periodic_command, crontab

# by default do not send emails
EMAIL_STATUS_CHECK = getattr(settings, 'SPIDER_EMAIL_STATUS_CHECK', False)


@periodic_command(crontab(minute='*/30'))
def check_health():
    errors = []
    for profile in SpiderProfile.objects.all():
        status_check = profile.check_health()
        if not status_check.is_ok():
            errors.append(status_check)

    if errors and EMAIL_STATUS_CHECK:
        message = render_to_string('spider/email/status_check.txt',
                                   {'status_check_list': errors})
        mail_admins('Spider status check error email',
                    message.strip(),
                    fail_silently=True)


@queue_command
def run_spider(session_id):
    session = SpiderSession.objects.get(pk=session_id)
Esempio n. 19
0
import datetime
from djutils.queue.decorators import queue_command, periodic_command, crontab


@queue_command
def testcommand(a, b):
    print a / b


@periodic_command(crontab())
def bloweveryodd():
    now = datetime.datetime.now()
    if now.minute % 2 == 0:
        raise ValueError("ppooopppp")
Esempio n. 20
0
import datetime

from django.conf import settings

from djutils import dashboard
from djutils.dashboard.models import Panel, PanelData
from djutils.queue.decorators import periodic_command, crontab

dashboard.autodiscover()

# set to 0 or None to prevent data from expiring
EXPIRATION_DAYS = getattr(settings, 'PANEL_DATA_EXPIRATION_DAYS', 7)

@periodic_command(crontab())
def update_panels():
    """
    Simple task which updates the dashboard panels every minute
    """
    Panel.objects.update_panels()

@periodic_command(crontab(minute=0, hour='*'))
def generate_hourly_aggregates():
    Panel.objects.generate_hourly_aggregates()

@periodic_command(crontab(minute=0, hour=0))
def generate_daily_aggregates():
    Panel.objects.generate_daily_aggregates()

@periodic_command(crontab(minute=0, hour=0))
def remove_old_panel_data():
    """
Esempio n. 21
0

@queue_command
def throw_error():
    raise BampfException("bampf")


class TestPeriodicCommand(PeriodicQueueCommand):
    def execute(self):
        User.objects.create_user("thirty", "thirty", "thirty")

    def validate_datetime(self, dt):
        return crontab(minute="*/30")(dt)


@periodic_command(crontab(minute="*/15"))
def every_fifteen():
    User.objects.create_user("fifteen", "fifteen", "fifteen")


class QueueTest(TestCase):
    def setUp(self):
        self.orig_always_eager = getattr(settings, "QUEUE_ALWAYS_EAGER", False)
        settings.QUEUE_ALWAYS_EAGER = False

        self.dummy = User.objects.create_user("username", "*****@*****.**", "password")
        self.consumer_options = ObjectDict(
            logfile="", delay=0.1, backoff=2, max_delay=0.4, no_periodic=False, threads=2, verbosity=1
        )
        invoker.flush()