def runSynSvc(name, item, sbus, tags=(), **props): ''' Add an object as a synapse service. Args: name (str): Name of the service. item (object): Callable service object. sbus (s_telepath.Proxy): Telepath Proxy object pointing to a ServiceBus. tags: **props: Additional props to make available about the service. Examples: Share the woot object as a service named 'syn.woot':: woot = Woot() sbus = s_telepath.openurl('tcp://1.2.3.4:90/syn.svcbus') runSynSvc('syn.woot', woot, sbus) Returns: str: The iden of the instance of the service on the ServiceBus. ''' iden = s_common.guid() sbus.push(iden, item) sbus.push(name, item) hostinfo = s_thishost.hostinfo tags = list(tags) names = s_reflect.getClsNames(item) tags.extend(['class.%s' % n for n in names]) tags.append(name) props['name'] = name props['tags'] = tags props['hostinfo'] = hostinfo props['hostname'] = hostinfo.get('hostname') def onTeleSock(mesg): if not sbus.isfini: sbus.iAmSynSvc(iden, props) def svcHeartBeat(): if sbus.isfini: return sbus.call('iAmAlive', iden) s_glob.sched.insec(30, svcHeartBeat) svcHeartBeat() sbus.on('tele:sock:init', onTeleSock) sbus.iAmSynSvc(iden, props) return iden
def runSynSvc(name, item, sbus, tags=(), **props): ''' Add an object as a synapse service. Example: woot = Woot() sbus = s_telepath.openurl('tcp://1.2.3.4:90/syn.svcbus') runSynSvc('syn.woot', woot, sbus) ''' iden = s_common.guid() sbus.push(iden, item) sbus.push(name, item) sched = s_sched.getGlobSched() hostinfo = s_thishost.hostinfo tags = list(tags) names = s_reflect.getClsNames(item) tags.extend(['class.%s' % n for n in names]) tags.append(name) props['name'] = name props['tags'] = tags props['hostinfo'] = hostinfo props['hostname'] = hostinfo.get('hostname') def onTeleSock(mesg): if not sbus.isfini: sbus.iAmSynSvc(iden, props) def svcHeartBeat(): if sbus.isfini: return sbus.call('iAmAlive', iden) sched.insec(30, svcHeartBeat) svcHeartBeat() sbus.on('tele:sock:init', onTeleSock) sbus.iAmSynSvc(iden, props) return iden
def test_reflect_getClsNames(self): foo = Foo() names = s_reflect.getClsNames(foo) self.isin('synapse.eventbus.EventBus', names) self.isin('synapse.tests.test_lib_reflect.Foo', names)
def test_reflect_getClsNames(self): foo = Foo() names = s_reflect.getClsNames(foo) self.isin('synapse.tests.test_lib_reflect.Lol', names) self.isin('synapse.tests.test_lib_reflect.Foo', names)