Esempio n. 1
0
 def handle(self, *args, **options):
     logger = log(self)
     logger.info(u'Pending CoA job started')
     logger.info('Waiting for CoA is unlocked...')
     while coa_is_locked():
         sleep(0.2)
     lock_coa()
     try:
         for coa in CoaQueue.objects.all():
             coa.run()
             sleep(0.05)
     except:
         logger.critical(u'PCJ catched exception: [{0}] {1}'.format(*sys.exc_info()))
     logger.info(u'Pending CoA job finished')
     unlock_coa()
Esempio n. 2
0
    def handle(self, *args, **options):
        logger = log(self)
        logger.info('Start services refresh')
        counter = 0
        skipped = 0
        failed = 0

        qs = UserNotificationRecord.objects.get_active().filter(is_completed=False)
        if options['limit'] > 0:
            qs = qs[:options['limit']]

        logger.info('Waiting for CoA is unlocked...')
        while coa_is_locked():
            sleep(0.2)
        lock_coa()
        for record in qs:

            if counter > 0 and counter % settings.COA_BLOCK_SIZE == 0:
                unlock_coa()
                logger.info('Records are refreshed: {}. Waiting for the next block...'.format(counter))
                sleep(settings.COA_BLOCK_DELAY)
                logger.info('Waiting for CoA is unlocked...')
                while coa_is_locked():
                    sleep(0.2)
                lock_coa()

            return_code = record.notification.coa.run(record.uid)
            if return_code is None:
                skipped += 1
            elif return_code == 0:
                counter += 1
                failed += 1
            else:
                counter += 1
                record.refreshed = datetime.now()
                record.save()
                sleep(settings.COA_MESSAGE_INTERVAL)
        unlock_coa()
        logger.info('Services refresh finished')