def v9_application(): print 'Starting [%s] Service ....' % app_name config = openerp.tools.config # 使用celery去触发定时器. period_sec = 60 if 'cron_by_celery_beats' in config.options: print "NO CRON TRIGGER,PLEASE ENABLE CELERY BEATS!!" elif 'cron_by_celery_worker' in config.options: print "Using UWSGI TIMER TO TRIGGER CRON IN CELERY WORKER!" uwsgi.register_signal(99, "mule1", celery_cron_trigger) uwsgi.add_rb_timer(99, period_sec) else: uwsgi.register_signal(99, "mule1", cron_works) uwsgi.add_rb_timer(99, period_sec) # else: # uwsgi.register_signal(99, "mule1", cron_works) # # uwsgi.register_signal(101,"mule2", notify_wechat_news) # print 'Register Signal 99 for mule1 as Cron workers' # linux 2.6.25以下内核.不支持timerfd.所以使用rb_timer. # uwsgi.add_rb_timer(101,60) # uwsgi.register_signal(100, "workers", v7_reload) # uwsgi.register_signal(101, "workers", service_active) # uwsgi.register_signal(102, "workers", service_deactive) return application2
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)
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)
def add_rb_timer(self, signum, seconds, iterations=0): ''' Add an user-space (red-black tree backed) timer. 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_rb_timer(signum, seconds, iterations=0)
def start_insert_timer(app): global insert_timer_started if insert_timer_started: return False insert_timer_started = True interval = app.config["INSERT_INTERVAL"] if uwsgi: uwsgi.register_signal(131, "workers", insert_timer_tick) uwsgi.add_rb_timer(131, interval) return True else: import threading def insert_timer_tick_loop(): while 1: sleep(interval) insert_timer_tick() thread = threading.Thread(target=insert_timer_tick_loop, name="insert timer") thread.setDaemon(True) thread.start() return True
def __call__(self, f): uwsgi.register_signal(self.num, self.target, f) uwsgi.add_rb_timer(self.num, self.secs) return f
return ("200 OK", {"X-Accel-Redirect": img}, "OK") else: return ("404 Not Found", {}, "404") if pfx == "/c/": url = self.get_url(banner_id) if url: self.clk_cache[banner_id] += 1 return ("302 OK", {"Location": url}, url) else: return ("404 Not Found", {}, "404") def __call__(self, environ, start_response): resp = self.serve(environ["PATH_INFO"]) if resp: resp[1]["Content-Length"] = str(len(resp[2])) start_response(resp[0], resp[1].items()) return resp[2] else: return self.next_application(environ, start_response) def commit_banners(x): banner_server.commit() from wsgiref.simple_server import demo_app application = banner_server = BannerServer(demo_app) uwsgi.register_signal(42, 'workers', commit_banners) uwsgi.add_rb_timer(42, 5)