Example #1
0
 def disable_frontage(self):
     SchedulerState.clear_user_app_queue()
     c_app = SchedulerState.get_current_app()
     if c_app:
         self.stop_app(c_app,
                     Fap.CODE_CLOSE_APP,
                     'The admin disabled Arbalet Frontage')
Example #2
0
def quit_user_app(user):
    c_app = SchedulerState.get_current_app()
    removed = False
    if is_admin(user) or c_app.get('userid', False) == user['userid']:
        SchedulerState.stop_app_request(user)
        removed = True
    return jsonify(removed=removed)
Example #3
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 #4
0
def admin_app_quit(user):
    if is_admin(user):
        if (SchedulerState.get_current_app()['name'] == "Snap"):
            Websock.set_grantUser({'id': "turnoff", 'username': "******"})
        removed = SchedulerState.stop_forced_app_request(user)
        return jsonify(removed=removed)
    else:
        abort(403, "Forbidden Bru")
    return '', 204
Example #5
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())
Example #6
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())
Example #7
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 #8
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()
Example #9
0
def set_is_alive_current_app(user):
    SchedulerState.set_is_alive(user)
    c_app = SchedulerState.get_current_app()
    keep_alive = "userid" in c_app and c_app['userid'] == user['userid']
    return jsonify(keepAlive=keep_alive)
Example #10
0
 def get(self, user):
     while SchedulerState.is_event_lock():
         pass
     return jsonify(SchedulerState.get_current_app())