Example #1
0
    def testCronCleanCommand(self):
        """
        Test that the ``cron_clean`` command runs properly.
        """
        # Pick the shortest running Job
        job = sorted(Job.objects.due().filter(command="test_sleeper"),
                     key=lambda j: int(j.args))[0]

        # Run the job 5 times
        for i in range(5):
            job.run(update_heartbeat=0)

        # Ensure that we have 5 Log objects
        self.assertEqual(Log.objects.count(), 1)

        # Ensure we can convert a log instances to unicode.
        s = six.text_type(Log.objects.all()[0])
        self.assertTrue(s.startswith('Sleep '), s)

        # Now clean out the logs that are older than 0 minutes (all of them)
        #call_command('cron_clean', 'minutes', '0')
        Log.cleanup()

        # Ensure that we have 0 Log objects
        self.assertEqual(Log.objects.count(), 0)
Example #2
0
 def testCronCleanCommand(self):
     """
     Test that the ``cron_clean`` command runs properly.
     """
     # Pick the shortest running Job
     job = sorted(
         Job.objects.due().filter(command="test_sleeper"),
         key=lambda j: int(j.args))[0]
     
     # Run the job 5 times
     for i in range(5):
         job.run(update_heartbeat=0)
     
     # Ensure that we have 5 Log objects
     self.assertEqual(Log.objects.count(), 1)
     
     # Ensure we can convert a log instances to unicode.
     s = six.text_type(Log.objects.all()[0])
     self.assertTrue(s.startswith('Sleep '), s)
     
     # Now clean out the logs that are older than 0 minutes (all of them)
     #call_command('cron_clean', 'minutes', '0')
     Log.cleanup()
     
     # Ensure that we have 0 Log objects
     self.assertEqual(Log.objects.count(), 0)
Example #3
0
 def handle(self, *args, **options):
             
     if len(args) != 2:
         sys.stderr.write(
             'Command requires two arguments. '
             'Unit (weeks, days, hours or minutes) and interval.\n')
         return
     else:
         unit = str(args[0])
         if unit not in ['weeks', 'days', 'hours', 'minutes']:
             sys.stderr.write('Valid units are weeks, days, hours or minutes.\n')
             return 1
         try:
             amount = int(args[1]) 
         except ValueError:
             sys.stderr.write('Interval must be an integer.\n')
             return 1
     kwargs = {unit: amount}
     time_ago = timezone.now() - timedelta(**kwargs)
     Log.cleanup(time_ago)
    def handle(self, *args, **options):

        if len(args) != 2:
            sys.stderr.write(
                'Command requires two arguments. '
                'Unit (weeks, days, hours or minutes) and interval.\n')
            return
        else:
            unit = str(args[0])
            if unit not in ['weeks', 'days', 'hours', 'minutes']:
                sys.stderr.write(
                    'Valid units are weeks, days, hours or minutes.\n')
                return 1
            try:
                amount = int(args[1])
            except ValueError:
                sys.stderr.write('Interval must be an integer.\n')
                return 1
        kwargs = {unit: amount}
        time_ago = timezone.now() - timedelta(**kwargs)
        Log.cleanup(time_ago)
 def handle( self, *args, **options ):
     from chroniker.models import Log
     from datetime import datetime, timedelta
             
     if len( args ) != 2:
         sys.stderr.write('Command requires two arguments. Unit (weeks, days, hours or minutes) and interval.\n')
         return
     else:
         unit = str( args[ 0 ] )
         if unit not in [ 'weeks', 'days', 'hours', 'minutes' ]:
             sys.stderr.write('Valid units are weeks, days, hours or minutes.\n')
             return
         try:
             amount = int( args[ 1 ] ) 
         except ValueError:
             sys.stderr.write('Interval must be an integer.\n')
             return
     kwargs = { unit: amount }
     time_ago = datetime.now() - timedelta( **kwargs )
     #Log.objects.filter( run_start_datetime__lte = time_ago ).delete()
     Log.cleanup(time_ago)
     
Example #6
0
    def handle(self, *args, **options):
        from chroniker.models import Log
        from datetime import datetime, timedelta

        if len(args) != 2:
            sys.stderr.write(
                'Command requires two arguments. Unit (weeks, days, hours or minutes) and interval.\n'
            )
            return
        else:
            unit = str(args[0])
            if unit not in ['weeks', 'days', 'hours', 'minutes']:
                sys.stderr.write(
                    'Valid units are weeks, days, hours or minutes.\n')
                return
            try:
                amount = int(args[1])
            except ValueError:
                sys.stderr.write('Interval must be an integer.\n')
                return
        kwargs = {unit: amount}
        time_ago = datetime.now() - timedelta(**kwargs)
        #Log.objects.filter( run_start_datetime__lte = time_ago ).delete()
        Log.cleanup(time_ago)
Example #7
0
 def handle(self, *args, **options):
     unit = options['unit']
     amount = options['amount']
     kwargs = {unit: amount}
     time_ago = timezone.now() - timedelta(**kwargs)
     Log.cleanup(time_ago)