Example #1
0
 def keep_alive_waiting_app(self):
     queue = SchedulerState.get_user_app_queue()
     for c_app in list(queue):
         # Not alive since last check ?
         if time.time() > (c_app['last_alive'] +
                           SchedulerState.DEFAULT_KEEP_ALIVE_DELAY):
             queue.remove(c_app)
Example #2
0
    def print_scheduler_info(self):
        if self.count % 100 == 0:
            self.count = 0
            logging.info(" ========== Scheduling ==========")
            logging.info("-------- Geometry")
            logging.info("\t\t {} rows * {} cols".format(
                SchedulerState.get_rows(), SchedulerState.get_cols()))
            logging.info("-------- Disabled")
            logging.info("\t\t {}".format(SchedulerState.get_disabled()))
            logging.info("-------- Enable State")
            logging.info(SchedulerState.get_enable_state())
            logging.info("-------- Is Frontage Up?")
            logging.info(SchedulerState.is_frontage_on())
            logging.info("-------- Usable?")
            logging.info(SchedulerState.usable())
            logging.info("-------- Current App")
            logging.info(SchedulerState.get_current_app())
            logging.info('Forced App ? {}'.format(
                SchedulerState.get_forced_app()))
            logging.info("---------- Waiting Queue")
            logging.info(SchedulerState.get_user_app_queue())
            if SchedulerState.get_enable_state() == 'scheduled':
                logging.info("---------- Scheduled ON")
                logging.info(SchedulerState.get_scheduled_on_time().strftime(
                    "%d-%m-%Y %H:%M:%S UTC+00"))
                logging.info("---------- Scheduled OFF")
                logging.info(SchedulerState.get_scheduled_off_time().strftime(
                    "%d-%m-%Y %H:%M:%S UTC+00"))
                logging.info("---------- TIME NOW")
                logging.info(datetime.datetime.now().strftime(
                    "%d-%m-%Y %H:%M:%S UTC+00"))

        self.count += 1
Example #3
0
 def print_scheduler_info(self):
     if self.count % 10 == 0:
         self.count = 0
         print_flush(" ========== Scheduling ==========")
         print_flush("-------- Enable State")
         print_flush(SchedulerState.get_enable_state())
         print_flush("-------- Is Frontage Up?")
         print_flush(SchedulerState.is_frontage_on())
         print_flush("-------- Usable?")
         print_flush(SchedulerState.usable())
         print_flush("-------- Current App")
         print_flush(SchedulerState.get_current_app())
         print_flush('Forced App ?', SchedulerState.get_forced_app())
         print_flush("---------- Waiting Queue")
         print_flush(SchedulerState.get_user_app_queue())
         if SchedulerState.get_enable_state() == 'scheduled':
             print_flush("---------- Scheduled ON")
             print_flush(SchedulerState.get_scheduled_on_time())
             print_flush("---------- Scheduled OFF")
             print_flush(SchedulerState.get_scheduled_off_time())
     self.count += 1
Example #4
0
    def check_app_scheduler(self):
        # check keep alive app (in user waiting app Q)
        self.keep_alive_waiting_app()

        # collect usefull struct & data
        queue = SchedulerState.get_user_app_queue()  # User waiting app
        c_app = SchedulerState.get_current_app()  # Current running app
        now = datetime.datetime.now()

        forced_app = SchedulerState.get_forced_app_request()

        # Is a app running ?
        if c_app:
            close_request, close_userid = SchedulerState.get_close_app_request()
            if close_request:
                message = Fap.CODE_CLOSE_APP if close_userid != c_app['userid'] else None
                print_flush('## Stopping app upon user reques [check_app_scheduler]')
                self.stop_app(c_app, message, 'Executing requested app closure')
                redis.set(SchedulerState.KEY_STOP_APP_REQUEST, '{}')
                return
            if len(forced_app) > 0 and not SchedulerState.get_forced_app():
                print_flush('## Closing previous app for forced one [check_app_scheduler]')
                SchedulerState.clear_user_app_queue()
                self.stop_app(c_app, Fap.CODE_CLOSE_APP, 'The admin started a forced app')
                return
            # do we kill an old app no used ? ?
            if self.keep_alive_current_app(c_app):
                return
            # is expire soon ?
            if not c_app.get('is_default', False) and now > (datetime.datetime.strptime(c_app['expire_at'], "%Y-%m-%d %H:%M:%S.%f") - datetime.timedelta(seconds=EXPIRE_SOON_DELAY)):
                if not SchedulerState.get_expire_soon():
                    Fap.send_expires_soon(EXPIRE_SOON_DELAY, c_app['username'], c_app['userid'])
            # is the current_app expired ?
            if self.app_is_expired(c_app) or c_app.get('is_default', False):
                # is the current_app a FORCED_APP ?
                if SchedulerState.get_forced_app():
                    print_flush('## Stopping expired forced app [check_app_scheduler]')
                    self.stop_app(c_app)
                    return
                # is some user-app are waiting in queue ?
                if len(queue) > 0:
                    next_app = queue[0]
                    self.stop_current_app_start_next(queue, c_app, next_app)
                    return
                else:
                    # is a defautl scheduled app ?
                    if c_app.get('is_default', False) and self.app_is_expired(c_app):
                        print_flush('## Stopping expired default scheduled app [check_app_scheduler]')
                        self.stop_app(c_app)
                        return
                    # it's a USER_APP, we let it running, do nothing
                    else:
                        pass
        else:
            if len(forced_app) > 0 and not SchedulerState.get_forced_app():
                print_flush("## Starting {} [FORCED]".format(forced_app['name']))
                SchedulerState.set_event_lock(True)
                SchedulerState.clear_forced_app_request()
                start_forced_fap.apply_async(args=[forced_app], queue='userapp')
                redis.set(SchedulerState.KEY_FORCED_APP, 'True')
                return
            # is an user-app waiting in queue to be started ?
            elif len(queue) > 0:
                SchedulerState.set_event_lock(True)
                start_fap.apply_async(args=[queue[0]], queue='userapp')
                print_flush(" Starting {} [QUEUE]".format(queue[0]['name']))
                return
            else:
                return self.start_default_app()