コード例 #1
0
def update_current_prisons(**kwargs):
    job = ScheduledCommand(
        name='update_current_prisons',
        arg_string='',
        cron_entry='*/10 * * * *',
        delete_after_next=True
    )
    job.save()
コード例 #2
0
def update_current_prisons(*args, **kwargs):
    job = ScheduledCommand(
        name='update_current_prisons',
        arg_string='',
        cron_entry='*/10 * * * *',
        delete_after_next=True
    )
    job.save()
コード例 #3
0
 def test_not_due_command_is_not_scheduled(self):
     command = ScheduledCommand(
         name='load_test_data',
         arg_string='',
         cron_entry='*/10 * * * *',
         next_execution=timezone.now() + timedelta(minutes=5)
     )
     command.save()
     self.assertFalse(command.is_scheduled())
コード例 #4
0
 def test_command_deleted_when_flag_set(self):
     command = ScheduledCommand(
         name='load_test_data',
         arg_string='--number-of-prisoners 60 --number-of-transactions 70',
         cron_entry='* * * * *',
         next_execution=timezone.now(),
         delete_after_next=True
     )
     command.save()
     run_commands = run_scheduled_commands.Command()
     with captured_stdout(), silence_logger():
         run_commands.handle()
     self.assertEqual(ScheduledCommand.objects.all().count(), 0)
コード例 #5
0
    def save(self):
        from performance.models import DigitalTakeup

        for nomis_id, credit_by_prison in self.credits_by_prison.items():
            DigitalTakeup.objects.update_or_create(
                defaults=credit_by_prison,
                date=self.date,
                prison_id=nomis_id,
            )

        datestr = self.date.strftime('%Y-%m-%dT00:00:00')
        job = ScheduledCommand(
            name='update_performance_platform',
            arg_string='--resources transactions-by-channel-type --timestamp %s' % datestr,
            cron_entry='*/10 * * * *',
            delete_after_next=True
        )
        job.save()
コード例 #6
0
    def save(self):
        from performance.models import DigitalTakeup

        for nomis_id, credit_by_prison in self.credits_by_prison.items():
            DigitalTakeup.objects.update_or_create(
                defaults=credit_by_prison,
                date=self.date,
                prison_id=nomis_id,
            )

        datestr = self.date.strftime('%Y-%m-%dT00:00:00')
        job = ScheduledCommand(
            name='update_performance_platform',
            arg_string='--resources transactions-by-channel-type --timestamp %s'
            % datestr,
            cron_entry='*/10 * * * *',
            delete_after_next=True)
        job.save()
コード例 #7
0
    def test_command_running(self):
        command = ScheduledCommand(
            name='load_test_data',
            arg_string='--number-of-prisoners 60 --number-of-transactions 70',
            cron_entry='* * * * *',
            next_execution=timezone.now()
        )
        command.save()
        run_commands = run_scheduled_commands.Command()
        with captured_stdout() as stdout, silence_logger():
            run_commands.handle()

        stdout = stdout.getvalue()
        self.assertIn('Making test users', stdout)
        self.assertIn('random credits', stdout)

        from prison.models import PrisonerLocation
        self.assertEqual(PrisonerLocation.objects.count(), 60)

        from transaction.models import Transaction
        self.assertEqual(Transaction.objects.count(), 70)
コード例 #8
0
 def test_newly_created_command_is_scheduled(self):
     command = ScheduledCommand(
         name='load_test_data', arg_string='', cron_entry='* * * * *'
     )
     command.save()
     self.assertTrue(timezone.now() - command.next_execution < timedelta(minutes=1))