def main(): res = '' while res not in ('Y', 'y', u'д', u'Д'): res = raw_input( 'U must run whip and pool "test" with config shire.cfg... Done? (y/n)' ) cfg = Config() cfg.load('shire.cfg') db.initialize(cfg.get_db()) jobs = [] print('Run 10 jobs') for i in range(10): job_descr = TestDbJob.delay(config=cfg, pool='test', kwargs=dict(sleep=1)) jobs.append(job_descr) print('Wait completion') while len(jobs): for job_descr in jobs[:]: if JobEntry.get(JobEntry.id == job_descr.id).status == JobEntry.STATUS_ENDED: jobs.remove(job_descr) time.sleep(1) print('Check DB connects') for row in db.execute_sql( 'SELECT datname, numbackends FROM pg_stat_database'): print(row)
def __init__(self, database_getter): from shire.models import db try: is_closed = db.is_closed() except AttributeError: # Это неинициализированный Proxy is_closed = True self.need_manage = is_closed self.db = db if is_closed: db.initialize(database_getter())
def __init__(self, config, verbose=False): self.config = config self.verbose = verbose self.hostler_logger = create_logger('shire.hostler') if verbose: create_console_handler(self.hostler_logger) self.section = self.config.section_getter(self.config.HOSTLER_SECTION) db.initialize(self.config.get_db()) self.host = self.config.get(self.config.SHIRE_SECTION, {}).get(self.config.SHIRE_HOST, self.config.SHIRE_HOST_DEFAULT) self.already_checked = {}
def setUpClass(cls): cls.tmp_dir = tempfile.mkdtemp() cls.config = Config() cls.config.make_default() cls.config[Config.CONNECTION_SECTION][ Config.CONNECTION_DB_URL] = 'sqlite:///{}/test.db'.format( cls.tmp_dir) cls.config[Config.CONNECTION_SECTION][ Config.CONNECTION_REDIS_URL] = 'redis://localhost:6379/15' cls.config_path = os.path.join(cls.tmp_dir, 'shire.cfg') cls.config.save(cls.config_path) cls.redis = cls.config.get_redis() db.initialize(cls.config.get_db()) for model in (JobEntry, Limit, Queue, Crontab): model.create_table(True)
def __init__(self, config, verbose=False): self.config = config self.verbose = verbose self.whip_logger = create_logger('shire.whip') if verbose: create_console_handler(self.whip_logger) self.section = self.config.section_getter(self.config.WHIP_SECTION) db.initialize(self.config.get_db()) self.queue_limits = {} self.pool_limits = {} self.queue_to_pool = {} self.max_jobs_limit = int( self.section.get(self.config.WHIP_MAX_JOBS, self.config.WHIP_MAX_JOBS_DEFAULT)) self.redis_queue = QueueManager(self.config.get_redis()) self.host = self.section.get(self.config.SHIRE_HOST, self.config.SHIRE_HOST_DEFAULT)
def fork(self): pid = os.fork() if pid: return pid # унаследовали signal.signal(signal.SIGTERM, pool.terminate) # надо сказать инстансу пула, что мы теперь - workhorse self.pool.i_am_pool = False setproctitle.setproctitle('{} job_id={}'.format(SHIRE_WORKHORSE_PROCESS_NAME, self.job_id) + ' ' * 128) # отдельное соединение для потомка db.initialize(self.config.get_db()) try: self.run() except Exception as exc: self.log.exception('In job #{} with workhorse uuid {} (pool {}/{})'.format( self.job_id, self.uuid, self.pool.name, self.pool.uuid)) sys.exit(1) else: sys.exit(0) finally: db.close()