Ejemplo n.º 1
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
Ejemplo n.º 2
0
def status():
    c_app = SchedulerState.get_current_app()
    c_app_name = c_app.get('name', '') if c_app else ''
    return jsonify(is_usable=SchedulerState.usable(),
                   is_forced=SchedulerState.get_forced_app(),
                   current_app=c_app_name,
                   next_on_time=SchedulerState.get_scheduled_on_time().isoformat(),
                   state=SchedulerState.get_enable_state(),
                   current_time=datetime.datetime.now().isoformat())
Ejemplo n.º 3
0
def admin_enabled_scheduler(user):
    state = g.data.get('state', 'on')
    if state not in ['on', 'off', 'scheduled']:
        abort(415, "Incorrect state")

    SchedulerState.set_enable_state(state)
    return jsonify(is_usable=SchedulerState.usable(),
                   is_forced=SchedulerState.get_forced_app(),
                   state=SchedulerState.get_enable_state(),
                   current_time=datetime.datetime.utcnow().isoformat())
Ejemplo n.º 4
0
def status():
    c_app = SchedulerState.get_current_app()
    c_app_name = c_app.get('name', '') if c_app else ''
    on_time = SchedulerState.get_scheduled_on_time()
    if on_time is not None:
        on_time.isoformat()
    return jsonify(is_usable=SchedulerState.usable(),
                   is_forced=SchedulerState.get_forced_app(),
                   current_app=c_app_name,
                   next_on_time=on_time,
                   state=SchedulerState.get_enable_state(),
                   current_time=datetime.datetime.utcnow().isoformat(),
                   height=SchedulerState.get_rows(),
                   width=SchedulerState.get_cols(),
                   disabled=SchedulerState.get_disabled(),
                   version=SchedulerState.get_version())
Ejemplo n.º 5
0
    def run_scheduler(self):
        # check usable value, based on ON/OFF AND if a forced app is running
        SchedulerState.set_usable((not SchedulerState.get_forced_app()) and SchedulerState.is_frontage_on())
        enable_state = SchedulerState.get_enable_state()
        if enable_state == 'scheduled':
            self.check_on_off_table()
        elif enable_state == 'on':
            SchedulerState.set_frontage_on(True)
        elif enable_state == 'off':
            SchedulerState.set_frontage_on(False)

        if SchedulerState.is_frontage_on():
            self.check_app_scheduler()
        else:
            # improvement : add check to avoid erase in each loop
            self.disable_frontage()
            self.frontage.erase_all()
Ejemplo n.º 6
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
Ejemplo n.º 7
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()