def req(redis, _to, _data=None): if _to: Command(redis.name, _to, 'shutdown', _data).send(redis) else: for (key, value) in redis.instance.items(): value.exit() return None
def req(redis, _to, _data=None): if _to: Command(redis.name, _to, 'load-config', _data).send(redis) else: for (key, value) in redis.instance.items(): value.loadConfig() return None
def test_to(self): j = json.dumps({ '_from': 'A', '_to': 'B', '_command': 'Test', '_data': None }) jStr = Command('A', 'B', 'Test').to() assert jStr == j
def test_parse(self, mocker): c = Command.parse( json.dumps({ '_from': 'A', '_to': 'B', '_command': 'Test', '_data': None })) assert c._from == 'A' assert c._to == 'B' assert c._command == 'Test'
def run(self): while not self.stopped.wait(self.sleep): for each in self.ps.listen(): if each['type'] == 'message': cmd = Command.parse(each['data'].decode('utf-8')) if self.isMine(cmd): Commander.processRes( self, Command.parse(each['data'].decode('utf-8'))) else: self.print(each['data'].decode('utf-8')) elif each['type'] == 'subscribe': self.print( 'Channel %s subscribed, listening count %d.' % (each['channel'].decode('utf-8'), each['data']), logging.DEBUG) elif each['type'] == 'unsubscribe': self.print( 'Channel %s unsubscribed, listening count %d.' % (each['channel'].decode('utf-8'), each['data']), logging.DEBUG) if self.isExit(): self.ps.close()
def req(redis, _to, _data): Command(redis.name, _to, '--switch execute-script', _data).send(redis) return None
def req(redis, _to, _data=None): Command(redis.name, _to, 'heart-beat', _data).send(redis) return None
def test_init(self): c = Shutdown(Command('A', 'B', 'Test')) assert c._from == 'A' assert c._to == 'B' assert c._command == 'Test'
def test_res(self): c = Shutdown(Command('A', 'B', 'Test')) assert c.res(None) == c
def req(redis, _to, _data): if _to: Command(redis.name, _to, 'message', _data).send(redis) else: redis.print('You need to specify a process to send.') return None
def test_init(self): c = HeartBeat(Command('A', 'B', 'Test')) assert c._from == 'A' assert c._to == 'B' assert c._command == 'Test'
def test_req(self): c = Online(Command('A', 'B', 'Test')) assert c.req() == c
def test_init(self): c = Online(Command('A', 'B', 'Test')) assert c._from == 'A' assert c._to == 'B' assert c._command == 'Test'
def test_swap(self): c = Command('A', 'B', 'Test') c.swap() assert c._from == 'B' assert c._to == 'A'
def test_send(self, mocker): c = Command('A', 'B', 'Test') mMethod = mocker.patch.object(c, 'send') c.send(None) assert mMethod.called
def req(redis, _to='Status', _data=None): Command(redis.name, _to, '--status online', _data).send(redis) return None
def req(redis, _to, _data=None): Command(redis.name, _to, '--schedule sync', _data).send(redis) return None
def test_req(self): c = HeartBeat(Command('A', 'B', 'Test')) assert c.req() == c
def req(redis, _to, _data=None): Command(redis.name, _to, '--schedule load-folder', _data).send(redis) return None
def test_res(self): c = HeartBeat(Command('A', 'B', 'Test')) c.res(None) assert c._from == 'B' assert c._to == 'A' assert c._command == 'I\'m online bitch!'