Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A pynsq Reader that polls for a file to transparently enable/disable
import os.path
import logging
import tornado.ioloop
from nsq import Reader as BaseReader
from nsq import run
class Reader(BaseReader):
def __init__(self, *args, **kwargs):
max_in_flight = kwargs['max_in_flight']
kwargs['max_in_flight'] = 0
def check_disabled():
if os.path.exists("queuereaders/disable"):
if self.max_in_flight == max_in_flight:'[%s] disabling. setting max_in_flight = 0',
if self.max_in_flight == 0:'[%s] enabling. setting max_in_flight = %d',, max_in_flight)
# poll every second for the disabled file, and adjust max_in_flight as appropriate
self.disabled_watcher = tornado.ioloop.PeriodicCallback(check_disabled, 1000)
super(Reader, self).__init__(*args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.