def test_handle_shutdown_request_no_horse(self): """Mutate HerokuWorker so _horse_pid refers to non existent process and test handle_warm_shutdown_request""" w = HerokuWorker('foo') w._horse_pid = 19999 w.handle_warm_shutdown_request()
def test_handle_shutdown_request(self): """Mutate HerokuWorker so _horse_pid refers to an artificial process and test handle_warm_shutdown_request""" w = HerokuWorker('foo') path = os.path.join(self.sandbox, 'shouldnt_exist') p = Process(target=create_file_after_timeout, args=(path, 2)) p.start() self.assertEqual(p.exitcode, None) w._horse_pid = p.pid w.handle_warm_shutdown_request() p.join(2) self.assertEqual(p.exitcode, -34) self.assertFalse(os.path.exists(path))
def test_handle_shutdown_request(self, mock_logger_info): """Mutate HerokuWorker so _horse_pid refers to an artificial process and test handle_warm_shutdown_request""" w = HerokuWorker('foo') path = os.path.join(self.sandbox, 'shouldnt_exist') p = Process(target=create_file_after_timeout, args=(path, 2)) p.start() self.assertEqual(p.exitcode, None) w._horse_pid = p.pid w.handle_warm_shutdown_request() p.join(2) # would expect p.exitcode to be -34 self.assertEqual(p.exitcode, -34) self.assertFalse(os.path.exists(path)) mock_logger_info.assert_called_with('Killed horse pid %s', p.pid)
import time from redis import Redis from rq import Queue, Connection from rq.worker import HerokuWorker as Worker listen = ['high', 'default', 'low'] conn = Redis(host='redis', port=6379, db=0) if __name__ == '__main__': with Connection(conn): worker = Worker(map(Queue, listen)) worker.work()
def connect_worker(): with Connection(conn): worker = Worker(map(Q, listen)) worker.work()
port=config.REDIS_PORT, db=0, password=config.REDIS_PASSWORD) logger.info('attempting to connect to database at {}'.format( config.SQLALCHEMY_DATABASE_URI)) db = create_engine(config.SQLALCHEMY_DATABASE_URI) Session = sessionmaker(bind=db) # Note: no additional config required due to webhook.py # sending required values to telegram bot = Bot(config.TELEGRAM_TOKEN) # Bind worker to db and redis worker.bind(bot, Session, redis, State) with Connection(redis): rq_worker = Worker(map(Queue, listen)) # Set final logging things logging.getLogger('rq.worker').setLevel(logging.WARNING) logging.getLogger('telegram*').setLevel(logging.WARNING) # if not config.DEVELOPMENT: # logging.getLogger('transitions').setLevel(logging.WARNING) logger.info('worker started') rq_worker.work() except redis_exceptions.ConnectionError: logger.error('Unable to connect to redis') sleep(10)
def start_worker(): with Connection(CONN): log.info("Starting update worker") worker = Worker("updates") worker.work()
def start(self): log('Starting worker') with Connection(self._redis_client): worker = Worker(map(Queue, listen)) worker.work()