def __init__(self, uri, database, name='worker', log_capture=True, timeout=60): uri = parse_uri(uri) self.username = '******' # uri.get('username', 'default_user') self.password = uri.get('password', 'mq_password') self.con = psycopg2.connect( user=self.username, password=self.password, # sslmode='require', # sslrootcert='certs/ca.crt', # sslkey='certs/client.maxroach.key', # sslcert='certs/client.maxroach.crt', port=uri['port'], host=uri['address']) self.con.set_session(autocommit=True) self.cursor = self.con.cursor() self.name = name self.agent_id = None self.heartbeat_monitor = None self.lock = RLock() self.database = database self.capture = log_capture self.timeout = timeout
def __init__(self, uri, database): uri = parse_uri(uri) self.lock = RLock() self.zip = zipfile.ZipFile(uri.get('path', uri.get('address', None))) self._cache = {} self.format = 'json' # find the format self.queues(self.namespaces()[0]) self.index = defaultdict(list) self.should_build_index = defaultdict(lambda: True)
def __init__(self, uri, database, cursor=None): # When using this inside a dashbord it is executed in a multi threaded environment # You need to lock the cursor to not get some errors self.lock = RLock() if cursor is None: uri = parse_uri(uri) self.client = pymongo.MongoClient(host=uri['address'], port=int(uri['port'])) else: self.client = cursor self.database = database self.db = self.client[self.database]
def __init__(self, uri, database, name='worker', log_capture=True, timeout=60): mongodb_uri = uri.replace('mongo', 'mongodb') uri = parse_uri(uri) self.name = name if uri.get('username') is not None: self.client = pymongo.MongoClient(mongodb_uri) else: self.client = pymongo.MongoClient(host=uri['address'], port=int(uri['port'])) self.heartbeat_monitor = None self.capture = log_capture self.timeout = timeout self.database = database self.db = self.client[self.database]
def __init__(self, uri, database, location, join=None, clean_on_exit=True): self.location = location logs = f'{location}/logs' temp = f'{location}/tmp' external = f'{location}/extern' store = location os.makedirs(logs, exist_ok=True) os.makedirs(temp, exist_ok=True) os.makedirs(external, exist_ok=True) self.uri = parse_uri(uri) self.database = database self.location = location self.bin = COCKROACH_BIN.get(os.name) if self.bin is None: raise RuntimeError('Your OS is not supported') if not os.path.exists(self.bin): info('Using system binary') self.bin = 'cockroach' else: hash = COCKROACH_HASH.get(os.name) # db_uri = uri.replace('cockroach', 'postgresql') self.addrs = f'{self.uri["address"]}:{self.uri["port"]}' self.arguments = [ 'start', '--insecure', f'--listen-addr={self.addrs}', f'--external-io-dir={external}', f'--store={store}', f'--temp-dir={temp}', f'--log-dir={logs}', f'--pid-file={location}/cockroach_pid' ] if join is not None: self.arguments.append(f'--join={join}') self.manager: Manager = Manager() self.properties = self.manager.dict() self.properties['running'] = False self.clean_on_exit = clean_on_exit self._process: Process = None self.cmd = None self.client = None self.cursor = None
def __init__(self, uri, database, cursor=None): # When using this inside a dashbord it is executed in a multi threaded environment # You need to lock the cursor to not get some errors self.lock = RLock() self.uri = uri if cursor is None: mongodb_uri = uri.replace('mongo', 'mongodb') uri = parse_uri(uri) if uri.get('username') is not None: self.client = pymongo.MongoClient(mongodb_uri) else: self.client = pymongo.MongoClient(host=uri['address'], port=int(uri['port'])) else: self.client = cursor self.database = database self.db = self.client[self.database] self.last_times = []
def __init__(self, uri, database, location, clean_on_exit=True): options = parse_uri(uri) address = options['address'] port = options['port'] self.location = location self.data_path = f'{self.location}/db' self.pid_file = f'{self.location}/pid' os.makedirs(self.data_path, exist_ok=True) if os.path.exists(self.pid_file): raise RuntimeError('MongoDB is already alive') self.address = address self.port = int(port) self.location = location self.bin = 'mongod' self.loglines = [] if self.bin is None: raise RuntimeError('Your OS is not supported') if not os.path.exists(self.bin): info('Using system binary') self.bin = 'mongod' self.arguments = [ '--dbpath', self.data_path, '--wiredTigerCacheSizeGB', '1', '--port', str(port), '--bind_ip', address, '--pidfilepath', self.pid_file ] self.database = database self.manager: Manager = Manager() self.properties = self.manager.dict() self.properties['running'] = False self.clean_on_exit = clean_on_exit self._process: Process = None self.cmd = None
def __init__(self, database, uri=None, cursor=None, lock=None): # When using this inside a dashbord it is executed in a multi threaded environment # You need to lock the cursor to not get some errors self.database = database if cursor is None: uri = parse_uri(uri) self.con = psycopg2.connect( user=uri.get('username', 'root'), password=uri.get('password', 'mq_password'), # sslmode='require', # sslrootcert='certs/ca.crt', # sslkey='certs/client.maxroach.key', # sslcert='certs/client.maxroach.crt', port=uri['port'], host=uri['address']) self.con.set_session(autocommit=True) self.cursor = self.con.cursor() self.lock = RLock() else: self.cursor = cursor self.lock = lock
def new_monitor(uri, database, *args, **kwargs) -> QueueMonitor: options = parse_uri(uri) return _maybe(monitor_factory, options.get('scheme'))(uri, database, *args, **kwargs)
def new_client(uri, database, name='worker', log_capture=True, timeout=60) -> MessageQueue: options = parse_uri(uri) return _maybe(client_factory, options.get('scheme'))(uri, database, name, log_capture, timeout)
def new_server(uri, database, location='/tmp/queue/', clean_on_exit=True, join=None) -> QueueServer: options = parse_uri(uri) return _maybe(broker_factory, options.get('scheme'))(uri, database, location, join, clean_on_exit)