Exemplo n.º 1
0
def init_env_and_config(app):
    if not app.config['FLATPAGES_ROOT']:
        app.config['FLATPAGES_ROOT'] = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            '../content')
    if app.config['CONTENT_URL']:
        init_repo(app.config["FLATPAGES_ROOT"], app.config['CONTENT_URL'])
    else:
        if not os.path.isdir(app.config['FLATPAGES_ROOT']):
            os.mkdir(app.config['FLATPAGES_ROOT'])

    try:
        import uwsgi
    except ImportError:
        logger.info("uwsgi package not found, uwsgi_timer hasn't been set")
    else:
        def update_uwsgi(signum):
            flatpages_root = app.config["FLATPAGES_ROOT"]
            logger.debug("Udpating git repository at %s", flatpages_root)
            hasToReload = update_repo(flatpages_root)
            if hasToReload:
                logger.debug("Reloading flatpages…")
                uwsgi.reload()

        logger.debug("Registering repo update to uwsgi signal")
        uwsgi.register_signal(20, "", update_uwsgi)
        uwsgi.add_timer(20, 300)

    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    if not app.config.get('SECRET_KEY'):
        if not app.debug:
            logger.warning('SECRET_KEY not set. Using default Key.')
        app.config['SECRET_KEY'] = "yIhswxbuDCvK8a6EDGihW6xjNognxtyO85SI"
Exemplo n.º 2
0
    def prepare_bot(self, bot_core, models, settings, roles, addons):
        global initial_signal
        bot = bot_core(models, settings, roles)
        for a in addons:
            bot.insert_addon(a)
        bot.bind()

        def check_tasks(signum):
            bot.check_tasks()

        uwsgi.register_signal(initial_signal, "", check_tasks)
        uwsgi.add_timer(initial_signal, 10)
        initial_signal -= 1

        for k, v in roles.items():
            if v == "ADMIN":
                if has_uwsgi:
                    try:
                        db_chat = bot.models["Chats"].objects.get(
                            bot__name=bot.name, user_name=k)
                        bot.send_message(db_chat, "Бот перезапущен")
                    except:
                        print("No admin found")

        return bot
Exemplo n.º 3
0
    def __init__(self, target_temp):
        self._target_temp = target_temp
        self._timestep = 0
        self._MIN_VALID_TEMP = -5.0
        self._MAX_VALID_TEMP = 30.0
        self._READING_TICK = 5
        self._DELTA_OVERSHOOT_TEMP = 2.0
        self._SSR_PIN = 11
        self._compressor_state = True
        self._sensors = {}
        self._sensors['000001efbab6'] = 'top'
        self._sensors['000001efd9ac'] = 'bottom'
        self._sensors['000001eff556'] = 'beer'
        self._sensor_readings = deque(
            maxlen=int(60/self._READING_TICK)*len(W1.get_available_sensors())
        )

        logging.config.dictConfig(app.config['LOG_CONFIG'])
        self.logger = logging.getLogger('agent')

        if not app.config['DEBUG']:
            GPIO.setmode(GPIO.BOARD)
            GPIO.setup(self._SSR_PIN, GPIO.OUT)
            uwsgi.register_signal(9000, 'worker', self.run)
            uwsgi.add_timer(9000, 5)
            atexit.register(lambda: self.cleanup())

        if app.config['LOG_DEBUG']:
            self.logger.setLevel(logging.DEBUG)
        else:
            self.logger.setLevel(logging.WARN)

        self.logger.info("Agent started")
Exemplo n.º 4
0
def schedule(delay, func, *args):
    """
    Can be implemented using a spooler.
    https://uwsgi-docs.readthedocs.io/en/latest/PythonDecorators.html

    To make the uwsgi configuration simple, use the alternative implementation.
    """
    global _last_signal

    def sighandler(signum):
        now = int(time.time())
        key = 'scheduler_call_time_signal_' + str(signum)
        uwsgi.lock()
        try:
            updating = uwsgi.cache_get(key)
            if updating is not None:
                updating = int.from_bytes(updating, 'big')
                if now - updating < delay:
                    return
            uwsgi.cache_update(key, now.to_bytes(4, 'big'))
        finally:
            uwsgi.unlock()
        func(*args)

    signal_num = _last_signal
    _last_signal += 1
    uwsgi.register_signal(signal_num, 'worker', sighandler)
    uwsgi.add_timer(signal_num, delay)
    return True
Exemplo n.º 5
0
    def __init__(self, conf):

        super(uWSGIMixin, self).__init__(conf)

        class Lock():

            def __enter__(self):
                uwsgi.lock()

            def __exit__(self, exc_type, exc_val, exc_tb):
                uwsgi.unlock()

        def spooler(args):
            try:
                self.mailer.sendmail(args["subject"].decode('utf-8'), args["body"].decode('utf-8'))
            except smtplib.SMTPConnectError:
                return uwsgi.SPOOL_RETRY
            else:
                return uwsgi.SPOOL_OK

        uwsgi.spooler = spooler

        self.lock = Lock()
        self.mailer = SMTP(conf)
        self.cache = uWSGICache

        timedelta = conf.getint("moderation", "purge-after")
        purge = lambda signum: self.db.comments.purge(timedelta)
        uwsgi.register_signal(1, "", purge)
        uwsgi.add_timer(1, timedelta)

        # run purge once
        purge(1)
Exemplo n.º 6
0
def init_env_and_config(app):
    if not app.config['FLATPAGES_ROOT']:
        app.config['FLATPAGES_ROOT'] = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), '../content')
    if app.config['CONTENT_URL']:
        init_repo(app.config["FLATPAGES_ROOT"], app.config['CONTENT_URL'])
    else:
        if not os.path.isdir(app.config['FLATPAGES_ROOT']):
            os.mkdir(app.config['FLATPAGES_ROOT'])

    try:
        import uwsgi
    except ImportError:
        logger.info("uwsgi package not found, uwsgi_timer hasn't been set")
    else:

        def update_uwsgi(signum):
            flatpages_root = app.config["FLATPAGES_ROOT"]
            logger.debug("Udpating git repository at %s", flatpages_root)
            hasToReload = update_repo(flatpages_root)
            if hasToReload:
                logger.debug("Reloading flatpages…")
                uwsgi.reload()

        logger.debug("Registering repo update to uwsgi signal")
        uwsgi.register_signal(20, "", update_uwsgi)
        uwsgi.add_timer(20, 300)

    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    if not app.config.get('SECRET_KEY'):
        if not app.debug:
            logger.warning('SECRET_KEY not set. Using default Key.')
        app.config['SECRET_KEY'] = "yIhswxbuDCvK8a6EDGihW6xjNognxtyO85SI"
Exemplo n.º 7
0
    def init_socket_reaper(self):
        # start a greenlet that handle connection closing when idle
        logging.getLogger(__name__).info("spawning a socket reaper with gevent")
        gevent.spawn(self.socket_reaper_thread)

        # Use uwsgi timer if we are running in uwsgi without gevent.
        # When we are using uwsgi without gevent, idle workers won't run the greenlet, it will only
        # be scheduled when waiting for a response of an external service (kraken mostly)
        try:
            import uwsgi

            # In gevent mode we stop, no need to add a timer, the greenlet will be scheduled while waiting
            # for incomming request.
            if 'gevent' in uwsgi.opt:
                return

            logging.getLogger(__name__).info("spawning a socket reaper with  uwsgi timer")

            # Register a signal handler for the signal 1 of uwsgi
            # this signal will trigger the socket reaper and can be run by any worker
            def reaper_timer(signal):
                self.reap_sockets()

            uwsgi.register_signal(1, 'active-workers', reaper_timer)
            # Add a timer that trigger this signal every reaper_interval second
            uwsgi.add_timer(1, self.reaper_interval)
        except (ImportError, ValueError):
            # ImportError is triggered if we aren't in uwsgi
            # ValueError is raise if there is no more timer availlable: only 64 timers can be created
            # workers that didn't create a timer can still run the signal handler
            # if uwsgi dispatch the signal to them
            # signal are dispatched randomly to workers (not round robbin :()
            logging.getLogger(__name__).info(
                "No more uwsgi timer available or not running in uwsgi, only gevent will be used"
            )
Exemplo n.º 8
0
 def ready(self):      
     if has_uwsgi:
         from datacon.processing.base_economy import reduce_by_scheme
         print("Standard startup scheme - using uWSGI scheduler")
         uwsgi.register_signal(89, "", reduce_by_scheme)
         uwsgi.add_timer(89, 86400)
     else:
         print("Running without UWSGI (reduced functionality)")
Exemplo n.º 9
0
def initialize(signal_number=DEFAULT_TIMER_SIGNAL_NUMBER,
               update_period_s=DEFAULT_UPDATE_PERIOD_S):
    """Initialize metrics, must be invoked at least once prior to invoking any
    other method."""
    global initialized
    if initialized:
        return
    initialized = True
    uwsgi.add_timer(signal_number, update_period_s)
    uwsgi.register_signal(signal_number, MULE, emit)
Exemplo n.º 10
0
def initialize(signal_number=DEFAULT_TIMER_SIGNAL_NUMBER,
               update_period_s=DEFAULT_UPDATE_PERIOD_S):
    """Initialize metrics, must be invoked at least once prior to invoking any
    other method."""
    global initialized
    if initialized:
        return
    initialized = True
    uwsgi.add_timer(signal_number, update_period_s)
    uwsgi.register_signal(signal_number, MULE, emit)
Exemplo n.º 11
0
 def start(self, interval, now=False):
     signum = get_free_signal()
     uwsgi.register_signal(signum, '', self._handle_signal)
     uwsgi.add_timer(signum, interval)
     if now:
         try:
             self._handle_signal(signum)
         except Exception as e:
             print e
             pass
Exemplo n.º 12
0
    def execute_async(self):
        if not uwsgi:
            return

        self.register_signal(self.signal_handler)

        seconds = self.setup.get('seconds', 0)
        iterations = self.setup.get('iterations', None)

        if iterations is None:
            uwsgi.add_timer(self.signal_id, seconds)
        else:
            uwsgi.add_rb_timer(self.signal_id, seconds, iterations)
Exemplo n.º 13
0
    def execute_async(self):
        if not uwsgi:
            return

        self.register_signal(self.signal_handler)

        seconds = self.setup.get('seconds', 0)
        iterations = self.setup.get('iterations', None)

        if iterations is None:
            uwsgi.add_timer(self.signal_id, seconds)
        else:
            uwsgi.add_rb_timer(self.signal_id, seconds, iterations)
Exemplo n.º 14
0
    def __init__(self, conf):

        super(uWSGIMixin, self).__init__(conf)

        self.lock = multiprocessing.Lock()
        self.cache = uWSGICache

        timedelta = conf.getint("moderation", "purge-after")
        purge = lambda signum: self.db.comments.purge(timedelta)
        uwsgi.register_signal(1, "", purge)
        uwsgi.add_timer(1, timedelta)

        # run purge once
        purge(1)
Exemplo n.º 15
0
Arquivo: core.py Projeto: kod3r/isso
    def __init__(self, conf):

        super(uWSGIMixin, self).__init__(conf)

        self.lock = multiprocessing.Lock()
        self.cache = uWSGICache

        timedelta = conf.getint("moderation", "purge-after")
        purge = lambda signum: self.db.comments.purge(timedelta)
        uwsgi.register_signal(1, "", purge)
        uwsgi.add_timer(1, timedelta)

        # run purge once
        purge(1)
Exemplo n.º 16
0
 def add_timer(self, signum, seconds, iterations=0):
     ''' 
     signum : The signal number to raise.
     seconds : The interval at which to raise the signal.
     iterations : How many times to raise the signal. 0 (the default) means infinity.
     '''
     return uwsgi.add_timer(signum, seconds)
Exemplo n.º 17
0
    def set_periodically():
        if isinstance(update_after_seconds, int):

            uwsgi.register_signal(SIGNAL_SET_FAISS_INDEX, 'workers',
                                  set_faiss_index)

            if get_faiss_resources:
                uwsgi.register_signal(SIGNAL_SET_FAISS_RESOURCES, 'worker',
                                      set_faiss_resources)
                uwsgi.add_timer(SIGNAL_SET_FAISS_RESOURCES,
                                update_after_seconds)
            else:
                uwsgi.add_timer(SIGNAL_SET_FAISS_INDEX, update_after_seconds)

        else:
            print('Failed to set periodic faiss index updates')
            print('UPDATE_FAISS_AFTER_SECONDS must be an integer')
Exemplo n.º 18
0
def init_env_and_config(app):
    # default configuration
    app.config.from_pyfile(os.path.realpath("sipa/default_config.py"))
    # if local config file exists, load everything into local space.
    if 'SIPA_CONFIG_FILE' not in os.environ:
        os.environ['SIPA_CONFIG_FILE'] = os.path.realpath("config.py")
    try:
        app.config.from_envvar('SIPA_CONFIG_FILE', silent=True)
    except IOError:
        logger.warning("SIPA_CONFIG_FILE not readable: %s",
                       os.environ['SIPA_CONFIG_FILE'])
    else:
        logger.info("Successfully read config file %s",
                    os.environ['SIPA_CONFIG_FILE'])

    app.config.update({
        name[len("SIPA_"):]: value for name, value in os.environ.items()
        if name.startswith("SIPA_")
    })
    if app.config['FLATPAGES_ROOT'] == "":
        app.config['FLATPAGES_ROOT'] = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            '../content')
    if app.config['CONTENT_URL']:
        init_repo(app.config["FLATPAGES_ROOT"], app.config['CONTENT_URL'])
    else:
        if not os.path.isdir(app.config['FLATPAGES_ROOT']):
            os.mkdir(app.config['FLATPAGES_ROOT'])

    if os.getenv("SIPA_UWSGI", "False") == 'True':
        import uwsgi

        def update_uwsgi(signum):
            hasToReload = update_repo(app.config["FLATPAGES_ROOT"])
            if hasToReload:
                uwsgi.reload

        logger.info("Registering repo update to uwsgi_signal")
        uwsgi.register_signal(20, "", update_uwsgi)
        uwsgi.add_timer(20, 300)

    if not app.config['SECRET_KEY']:
        raise ValueError("SECRET_KEY must not be empty")
Exemplo n.º 19
0
def init_env_and_config(app):
    # default configuration
    app.config.from_pyfile(os.path.realpath("sipa/default_config.py"))
    # if local config file exists, load everything into local space.
    if 'SIPA_CONFIG_FILE' not in os.environ:
        os.environ['SIPA_CONFIG_FILE'] = os.path.realpath("config.py")
    try:
        app.config.from_envvar('SIPA_CONFIG_FILE', silent=True)
    except IOError:
        logger.warning("SIPA_CONFIG_FILE not readable: %s",
                       os.environ['SIPA_CONFIG_FILE'])
    else:
        logger.info("Successfully read config file %s",
                    os.environ['SIPA_CONFIG_FILE'])

    app.config.update({
        name[len("SIPA_"):]: value
        for name, value in os.environ.items() if name.startswith("SIPA_")
    })
    if app.config['FLATPAGES_ROOT'] == "":
        app.config['FLATPAGES_ROOT'] = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), '../content')
    if app.config['CONTENT_URL']:
        init_repo(app.config["FLATPAGES_ROOT"], app.config['CONTENT_URL'])
    else:
        if not os.path.isdir(app.config['FLATPAGES_ROOT']):
            os.mkdir(app.config['FLATPAGES_ROOT'])

    if os.getenv("SIPA_UWSGI", "False") == 'True':
        import uwsgi

        def update_uwsgi(signum):
            hasToReload = update_repo(app.config["FLATPAGES_ROOT"])
            if hasToReload:
                uwsgi.reload

        logger.info("Registering repo update to uwsgi_signal")
        uwsgi.register_signal(20, "", update_uwsgi)
        uwsgi.add_timer(20, 300)

    if not app.config['SECRET_KEY']:
        raise ValueError("SECRET_KEY must not be empty")
Exemplo n.º 20
0
def init(app):
    def update_commands(signal_id):
        log.debug('Updating commands...')
        from pajbot.models.command import CommandManager
        bot_commands = CommandManager(
            socket_manager=None,
            module_manager=ModuleManager(None).load(),
            bot=None).load(load_examples=True)
        app.bot_commands_list = bot_commands.parse_for_web()

        app.bot_commands_list.sort(key=lambda x: (x.id or -1, x.main_alias))
        del bot_commands

    update_commands(26)
    try:
        import uwsgi
        from uwsgidecorators import thread, timer
        uwsgi.register_signal(26, 'worker', update_commands)
        uwsgi.add_timer(26, 60 * 10)

        @thread
        @timer(60)
        def get_highlight_thumbnails(no_clue_what_this_does):
            from pajbot.web.models.thumbnail import StreamThumbnailWriter
            with DBManager.create_session_scope() as db_session:
                highlights = db_session.query(StreamChunkHighlight).filter_by(
                    thumbnail=None).all()
                if len(highlights) > 0:
                    log.info('Writing {} thumbnails...'.format(
                        len(highlights)))
                    StreamThumbnailWriter(app.bot_config['main']['streamer'],
                                          [h.id for h in highlights])
                    log.info('Done!')
                    for highlight in highlights:
                        highlight.thumbnail = True
    except ImportError:
        log.exception('Import error, disregard if debugging.')
        pass
    pass
Exemplo n.º 21
0
def init(app):
    def update_commands(signal_id):
        log.debug('Updating commands...')
        from pajbot.models.command import CommandManager
        bot_commands = CommandManager(
                socket_manager=None,
                module_manager=ModuleManager(None).load(),
                bot=None).load(load_examples=True)
        app.bot_commands_list = bot_commands.parse_for_web()

        app.bot_commands_list.sort(key=lambda x: (x.id or -1, x.main_alias))
        del bot_commands

    update_commands(26)
    try:
        import uwsgi
        from uwsgidecorators import thread, timer
        uwsgi.register_signal(26, 'worker', update_commands)
        uwsgi.add_timer(26, 60 * 10)

        @thread
        @timer(5)
        def get_highlight_thumbnails(no_clue_what_this_does):
            from pajbot.web.models.thumbnail import StreamThumbnailWriter
            with DBManager.create_session_scope() as db_session:
                highlights = db_session.query(StreamChunkHighlight).filter_by(thumbnail=None).all()
                if len(highlights) > 0:
                    log.info('Writing {} thumbnails...'.format(len(highlights)))
                    StreamThumbnailWriter(app.bot_config['main']['streamer'], [h.id for h in highlights])
                    log.info('Done!')
                    for highlight in highlights:
                        highlight.thumbnail = True
    except ImportError:
        log.exception('Import error, disregard if debugging.')
        pass
    pass
Exemplo n.º 22
0
jitsi = ServerList('jitsi_servers.lst', 'sounds/outgoingRinging.wav')
poll = ServerList('poll_servers.lst', 'images/date.png')
pad = ServerList('pad_servers.lst', None)
codimd = ServerList('codimd_servers.lst', 'screenshot.png')
cryptpad = ServerList('cryptpad_servers.lst', 'customize/images/AGPL.png')
etherpad = ServerList('etherpad_servers.lst', 'locales.json')
ethercalc = ServerList('ethercalc_servers.lst', 'static/img/davy/bg/home2.png')


def reload(signum):
    print("start reload")
    global jitsi
    global poll
    global pad
    global codimd
    global cryptpad
    global etherpad
    global ethercalc
    jitsi.renew()
    poll.renew()
    pad.renew()
    codimd.renew()
    cryptpad.renew()
    etherpad.renew()
    ethercalc.renew()
    print("finish reload")


uwsgi.register_signal(99, "", reload)
uwsgi.add_timer(99, 600)
Exemplo n.º 23
0
import os
import uwsgi
from CronOrder.ele import *
from CronOrder.ordermig import *
from CronOrder.method import *
from ProxyWork.method import *
import sys
reload(sys)
sys.setdefaultencoding('utf8')

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "SeaSite.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

uwsgi.register_signal(80, "", resetToken)
uwsgi.add_timer(80, 1800)
uwsgi.register_signal(82, "", getproxy)
uwsgi.add_cron(82, 0, 10, -1, -1, -1)
uwsgi.register_signal(84, "", getproxy)
uwsgi.add_cron(84, 0, 15, -1, -1, -1)
uwsgi.register_signal(86, "", checkproxy)
uwsgi.add_cron(86, 0, 9, -1, -1, -1)
uwsgi.register_signal(88, "", checkproxy)
uwsgi.add_cron(88, 0, 16, -1, -1, -1)
uwsgi.register_signal(90, "", migrateorder)
uwsgi.add_cron(90, 0, 0, -1, -1, -1)
Exemplo n.º 24
0
                print(element)
                element.unlink()


def delete_unused_files(signum):
    """Function called by uwsgi periodically
    Removes unused files, keeps the disk clean
    """
    print("Removing unused files...")
    delete_files(AUDIO_DIR)
    delete_files(TMP_DIR)
    delete_files(SPECS_DIR)


uwsgi.register_signal(1, '', delete_unused_files)
uwsgi.add_timer(1, UPLOADS_DELETION_TIME * 60)  # conversion to seconds


@print_execution_time
def generate_spectrograms(audio_filename, time_range, length, offset):
    """Transforms wav file excerpt into a spetrogram.
    It simply executes python script inside a shell.

    Returns:
        A preprocessor script's exit code
    """
    command = 'python {script_path} --input {audio_path} --output-dir {spec_dir} --start {start} --end {end} --segment-length {length} --segment-overlap-length {overlap}'.format(
        script_path=PROCESSOR_PATH,
        audio_path=AUDIO_DIR / audio_filename,
        spec_dir=SPECS_DIR,
        start=time_range[0],
Exemplo n.º 25
0
    print "task is finished  of signal %i" % (workerfinsihed)
    state = getmemorystate()
    del state["current_workers_tasks"][workerfinsihed]
    print state
    setmemorystate(state)


# main signal of routing
uwsgi.register_signal(10, "worker1", routing)
# gracefull reload
uwsgi.register_signal(99, "worker1", gracefull_stop)
uwsgi.register_signal(98, "worker1", gracefull_reload)
uwsgi.register_signal(97, "worker1", gracefull_start)
uwsgi.register_signal(96, "worker1", gracefull_suspend)

# register for all workers signal of finishing
for i in workers_signal:
    uwsgi.register_signal(signal_ending + i, "worker1", worker_end)

##every 2 seconds
uwsgi.add_timer(10, 60)

## initilize state default start work
state = {"working": True, "workers_tasks": [], "current_workers_tasks": {}}
setmemorystate(state)

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()
print "application has been started"
Exemplo n.º 26
0
def start_uwsgi_timer(freq, type_, callable_):
    import uwsgi
    uwsgi.register_signal(66, type_, callable_)
    uwsgi.add_timer(66, freq)
Exemplo n.º 27
0
    print state
    setmemorystate(state)


# main signal of routing
uwsgi.register_signal(10, "worker1", routing)
# gracefull reload
uwsgi.register_signal(99, "worker1", gracefull_stop)
uwsgi.register_signal(98, "worker1", gracefull_reload)

# register for all workers signal of finishing
for i in workers_signal:
    uwsgi.register_signal(signal_ending + i, "worker1", worker_end)

##every 2 seconds
uwsgi.add_timer(10, 2)

## initilize state
state = {"workers_tasks": [], "current_workers_tasks": {}}
setmemorystate(state)

#uwsgi.add_timer(99, 45)
#uwsgi.add_timer(95, 50)
#uwsgi.add_timer(98, 60)
#uwsgi.add_timer(97, 90)

#uwsgi.add_timer(98, 300)
# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
Exemplo n.º 28
0
            except:
                logging.exception('Failed to update')
            time.sleep(60)
    finally:
        uwsgi.unlock(signum)


logging.basicConfig(level=logging.INFO)

logging.getLogger(
    'botocore.vendored.requests.packages.urllib3.connectionpool').setLevel(
        logging.WARNING)
app = connexion.App(__name__)
app.add_api('swagger.yaml')
application = app.app

try:
    import uwsgi
    for i in range(1, 1 + PARALLEL):
        signum = i
        uwsgi.register_signal(signum, "", run_update)
        uwsgi.add_timer(signum, 10)

    # initialization for /metrics endpoint (ZMON support)
    uwsgi_metrics.initialize()
except Exception as e:
    print(e)

if __name__ == '__main__':
    app.run(port=8080)
Exemplo n.º 29
0
    bot_request = bot.get_player_bot_request(request)
    if bot_request:
        storage = Storage(bot_request.send_callback_factory,
                          cmd_pfx=bot.cmd_pfx)
        player = storage.get_player_state(bot_request.chatkey)
        chatflow = Chatflow(player, storage.world, bot.cmd_pfx)
        if bot_request.process_message(chatflow):  # bot-specific UI commands
            storage.release()
        else:
            chatflow.process_message(bot_request.message_text)
            storage.save()
        bot_request.send_messages()
    return b'OK'


def enact(*args):
    bot_request = bot.get_bot_request()
    storage = Storage(bot_request.send_callback_factory, cmd_pfx=bot.cmd_pfx)
    storage.world.enact()
    storage.save()
    bot_request.send_messages()


try:
    import uwsgi
except ImportError:
    pass
else:
    uwsgi.register_signal(30, "worker", enact)
    uwsgi.add_timer(30, settings.CYCLE_SECONDS)
Exemplo n.º 30
0
# this module will update a carbon server (used by the graphite tool: http://graphite.wikidot.com/)
# with requests count made by a Django app (and can track graphite itself as it is a Django app ;)
#
#
 
import os
import uwsgi
import time
from django.core.handlers.wsgi import WSGIHandler
 
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
 
CARBON_SERVER = "127.0.0.1:2003"
 
def update_carbon(signum):
    # connect to the carbon server
    carbon_fd = uwsgi.connect(CARBON_SERVER)
    # send data to the carbon server
    uwsgi.send(carbon_fd, "uwsgi.%s.requests %d %d\n" % (uwsgi.hostname, uwsgi.total_requests(), int(time.time())))
    # close the connection with the carbon server
    uwsgi.close(carbon_fd)
 
# register a new uwsgi signal (signum: 17)
uwsgi.register_signal(17, '', update_carbon)
 
# attach a timer of 10 seconds to signal 17
uwsgi.add_timer(17, 10)
 
# the Django app
application = WSGIHandler()
Exemplo n.º 31
0
 def __call__(self, f):
     uwsgi.register_signal(self.num, self.target, f)
     uwsgi.add_timer(self.num, self.secs)
     return f
Exemplo n.º 32
0
import os
import uwsgi
import time
from django.core.handlers.wsgi import WSGIHandler

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

CARBON_SERVER = "127.0.0.1:2003"


def update_carbon(signum):
    # connect to the carbon server
    carbon_fd = uwsgi.connect(CARBON_SERVER)
    # send data to the carbon server
    uwsgi.send(
        carbon_fd, "uwsgi.%s.requests %d %d\n" %
        (uwsgi.hostname, uwsgi.total_requests(), int(time.time())))
    # close the connection with the carbon server
    uwsgi.close(carbon_fd)


# register a new uwsgi signal (signum: 17)
uwsgi.register_signal(17, '', update_carbon)

# attach a timer of 10 seconds to signal 17
uwsgi.add_timer(17, 10)

# the Django app
application = WSGIHandler()
Exemplo n.º 33
0
def start_uwsgi_timer(freq, type_, callable_):
    import uwsgi
    uwsgi.register_signal(66, type_, callable_)
    uwsgi.add_timer(66, freq)
Exemplo n.º 34
0
    bot_commands = CommandManager(
            socket_manager=None,
            module_manager=ModuleManager(None).load(),
            bot=None).load(load_examples=True)
    bot_commands_list = bot_commands.parse_for_web()

    bot_commands_list = sorted(bot_commands_list, key=lambda x: (x.id or -1, x.main_alias))
    del bot_commands


update_commands(26)
try:
    import uwsgi
    from uwsgidecorators import thread, timer
    uwsgi.register_signal(26, "worker", update_commands)
    uwsgi.add_timer(26, 60 * 10)

    @thread
    @timer(5)
    def get_highlight_thumbnails(no_clue_what_this_does):
        from pajbot.web.models.thumbnail import StreamThumbnailWriter
        with DBManager.create_session_scope() as db_session:
            highlights = db_session.query(StreamChunkHighlight).filter_by(thumbnail=None).all()
            if len(highlights) > 0:
                log.info('Writing {} thumbnails...'.format(len(highlights)))
                StreamThumbnailWriter(config['main']['streamer'], [h.id for h in highlights])
                log.info('Done!')
                for highlight in highlights:
                    highlight.thumbnail = True
except ImportError:
    pass
Exemplo n.º 35
0
"""
WSGI config for tangosquadmilano project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
"""

from django.core.wsgi import get_wsgi_application
from socialcrawler.apps import crawl_facebook
from socialcrawler.apps import crawl_instagram
from uwsgi import add_timer
from uwsgi import register_signal

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tangosquadmilano.settings")

application = get_wsgi_application()

register_signal(1, "mule0", crawl_facebook)
add_timer(1, 3600)
register_signal(2, "mule0", crawl_instagram)
add_timer(2, 3600)
Exemplo n.º 36
0

def long_processing_trans_in(signum):

    uwsgi.lock()

    try:
        call_command("incoming_crypto_merger", "1489820322")
    except:
        traceback.print_exc()

    uwsgi.unlock()


uwsgi.register_signal(99, "", merged_command)
uwsgi.register_signal(95, "", monero_work)
uwsgi.register_signal(98, "", global_crypto_check)
uwsgi.register_signal(97, "", long_processing_trans_in)
uwsgi.register_signal(96, "", out_trans)

uwsgi.add_timer(99, 120)
uwsgi.add_timer(95, 90)
uwsgi.add_timer(98, 360)
uwsgi.add_timer(97, 60)
uwsgi.add_timer(96, 300)

#uwsgi.add_timer(98, 300)
# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
Exemplo n.º 37
0
    #		threads = threads.append(gevent.spawn(fetch_product,now_product.hkd))
    #		print "%i finished"%i
    product = JDProduct.query.all()
    ukd = [prod.hkd for prod in product]
    threads = [gevent.spawn(fetch_product, hkd) for hkd in ukd]
    gevent.joinall(threads)
    return "ok"


def three_minute_call(signum):
    """定时任务 每10分钟执行一次fetch_all"""
    fetch_all()


uwsgi.register_signal(99, "", three_minute_call)  #信号注册
uwsgi.add_timer(99, 600)  #定时器


@app.route('/api/sendmail')
def sendmail(hkd=0, price1=0, price2=0):
    """demo 发送邮件提醒价格变动"""
    sender = "*****@*****.**"
    receiver = "*****@*****.**"
    subject = "the price of %s has changed from %s to %s" % (hkd, price1,
                                                             price2)
    smtpserver = "smtp.126.com"
    username = "******"
    password = "******"

    msg = MIMEText("", 'text', 'utf-8')
    msg['Subject'] = Header(subject, 'utf-8')
Exemplo n.º 38
0
def init_index(setup_state):
    set_faiss_index()
    uwsgi.register_signal(UPDATE_INDEX_SIGNAL, "workers", update_index)
    uwsgi.register_signal(UPDATE_EMBED_SIGNAL, "worker", update_embed)
    uwsgi.add_timer(UPDATE_EMBED_SIGNAL, config.update_seconds)
Exemplo n.º 39
0
                                    # throttling
                                    time.sleep(60)
            except:
                logging.exception('Failed to update')
            time.sleep(60)
    finally:
        uwsgi.unlock(signum)


logging.basicConfig(level=logging.INFO)

logging.getLogger('botocore.vendored.requests.packages.urllib3.connectionpool').setLevel(logging.WARNING)
app = connexion.App(__name__)
app.add_api('swagger.yaml')
application = app.app

try:
    import uwsgi
    for i in range(1, 1 + PARALLEL):
        signum = i
        uwsgi.register_signal(signum, "", run_update)
        uwsgi.add_timer(signum, 10)

    # initialization for /metrics endpoint (ZMON support)
    uwsgi_metrics.initialize()
except Exception as e:
    print(e)

if __name__ == '__main__':
    app.run(port=8080)
Exemplo n.º 40
0
    bot_commands = CommandManager(
            socket_manager=None,
            module_manager=ModuleManager(None).load(),
            bot=None).load(load_examples=True)
    bot_commands_list = bot_commands.parse_for_web()

    bot_commands_list = sorted(bot_commands_list, key=lambda x: (x.id or -1, x.main_alias))
    del bot_commands


update_commands(26)
try:
    import uwsgi
    from uwsgidecorators import thread, timer
    uwsgi.register_signal(26, "worker", update_commands)
    uwsgi.add_timer(26, 60 * 10)

    @thread
    @timer(5)
    def get_highlight_thumbnails(no_clue_what_this_does):
        from pajbot.web.models.thumbnail import StreamThumbnailWriter
        with DBManager.create_session_scope() as db_session:
            highlights = db_session.query(StreamChunkHighlight).filter_by(thumbnail=None).all()
            if len(highlights) > 0:
                log.info('Writing {} thumbnails...'.format(len(highlights)))
                StreamThumbnailWriter(config['main']['streamer'], [h.id for h in highlights])
                log.info('Done!')
                for highlight in highlights:
                    highlight.thumbnail = True
except ImportError:
    pass
Exemplo n.º 41
0
   os.path.abspath(os.path.join(os.path.dirname(__file__), '../../application/website')),
   os.path.abspath(os.path.join(os.path.dirname(__file__), '../../application')),
   os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')),
   )

for path in paths:
   sys.path.insert(0,path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'application.settings.xsf_stage2'

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()


#################### Test uWSGI Cron begin ############################
## uwsgi.add_cron(signal, minute, hour, day, month, weekday)
## uwsgi.add_timer(signal, sec)

import uwsgi

from scripts.cron_job import *

for job_id, job in enumerate(jobs):
    uwsgi.register_signal(job_id, "", job['name'])
    if len(job['time']) == 1:
        uwsgi.add_timer(job_id, job['time'][0])
    else:
        uwsgi.add_cron(job_id, job['time'][0], job['time'][1], job['time'][2], job['time'][3], job['time'][4])

#################### Test uWSGI Cron end ############################
Exemplo n.º 42
0
import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "rcasite.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()


try:
    import uwsgi
    from django.core.management import call_command
    print("We have a uWSGI")

    def make_task_runner(task):
        def task_runner(unused):
            if uwsgi.i_am_the_lord(os.getenv("CFG_APP_NAME")):
                print("I am the lord.")
                print("Running %s" % task)
                call_command(task, interactive=False)
            else:
                print("I am not the lord.")
        return task_runner

    uwsgi.register_signal(100, "", make_task_runner('set_page_random_order'))
    uwsgi.add_timer(100, 60 * 60)  # Run every hour
except ImportError:
    print("We have no uWSGI")