Beispiel #1
0
    def _onSockFini(self):
        if self.isfini:
            return

        try:

            if not self._initTeleSock():
                sched = s_sched.getGlobSched()
                sched.insec( 1, self._onSockFini )

        except Exception as e:
            sched = s_sched.getGlobSched()
            sched.insec( 1, self._onSockFini )
Beispiel #2
0
    def _runSockFini(self):
        if self.isfini:
            return

        try:
            self._initTeleSock()
        except LinkErr as e:
            sched = s_sched.getGlobSched()
            sched.insec(1, self._runSockFini )
Beispiel #3
0
    def _runSockFini(self):
        if self.isfini:
            return

        try:
            self._initTeleSock()
        except LinkErr as e:
            sched = s_sched.getGlobSched()
            sched.insec(1, self._runSockFini )
Beispiel #4
0
    def test_sched_glob(self):
        sched = s_sched.getGlobSched()

        evt = threading.Event()
        data = {}

        def woot():
            data['woot'] = 'woot'
            evt.set()

        sched.insec(0.01, woot)

        evt.wait(timeout=3)
        self.eq(data.get('woot'), 'woot')
Beispiel #5
0
def runSynSvc(name, item, sbus, tags=()):
    '''
    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 = guid()

    sbus.push(iden, item)
    sbus.push(name, item)

    sched = s_sched.getGlobSched()
    hostinfo = s_thishost.hostinfo

    tags = list(tags)

    names = getClsNames(item)
    tags.extend(['class.%s' % n for n in names])

    tags.append(name)

    props = {}

    props['name'] = name
    props['tags'] = tags
    props['hostinfo'] = hostinfo

    def onTeleSock(mesg):
        if not sbus.isfini:
            sbus.iAmSynSvc(iden, props)

    def svcHeartBeat():
        if sbus.isfini:
            return

        sbus.iAmAlive(iden)
        sched.insec(30, svcHeartBeat)

    svcHeartBeat()

    sbus.on('tele:sock:init', onTeleSock)
    sbus.iAmSynSvc(iden, props)

    return iden
Beispiel #6
0
def runSynSvc(name, item, sbus, tags=()):
    '''
    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 = guid()

    sbus.push(iden,item)
    sbus.push(name,item)

    sched = s_sched.getGlobSched()
    hostinfo = s_thishost.hostinfo

    tags = list(tags)

    names = getClsNames(item)
    tags.extend( [ 'class.%s' % n for n in names ] )

    tags.append(name)

    props = {}

    props['name'] = name
    props['tags'] = tags
    props['hostinfo'] = hostinfo

    def onTeleSock(mesg):
        if not sbus.isfini:
            sbus.iAmSynSvc(iden, props)

    def svcHeartBeat():
        if sbus.isfini:
            return

        sbus.iAmAlive(iden)
        sched.insec(30, svcHeartBeat)

    svcHeartBeat()

    sbus.on('tele:sock:init', onTeleSock)
    sbus.iAmSynSvc(iden, props)

    return iden
Beispiel #7
0
    def test_sched_glob(self):
        sched = s_sched.getGlobSched()

        evt = threading.Event()
        data = {}

        def woot():
            data['woot'] = 'woot'
            evt.set()

        sched.insec( 0.01, woot )

        evt.wait(timeout=3)
        self.assertEqual( data.get('woot'), 'woot' )
Beispiel #8
0
    def __init__(self):
        EventBus.__init__(self)

        self.onfini(self._onBossFini)

        self.pool = None
        self.sched = s_sched.getGlobSched()

        self.joblock = threading.Lock()

        self._boss_jobs = {}
        self.joblocal = {}

        self.on('job:done', self._onJobDone)  # trigger job done
        self.on('job:fini', self._onJobFini)  # job is finished
Beispiel #9
0
    def __init__(self):
        EventBus.__init__(self)

        self.onfini( self._onBossFini )

        self.pool = None
        self.sched = s_sched.getGlobSched()

        self.joblock = threading.Lock()

        self._boss_jobs = {}
        self.joblocal = {}

        self.on('job:done', self._onJobDone )  # trigger job done
        self.on('job:fini', self._onJobFini )  # job is finished
Beispiel #10
0
    def __init__(self, maxtime=None, onmiss=None):
        EventBus.__init__(self)

        self.sched = s_sched.getGlobSched()
        self.onmiss = onmiss

        self.cache = {}
        self.lasthit = {}
        self.schevt = None
        self.maxtime = None
        self.cachelock = threading.Lock()

        self.onfini(self._onCacheFini)

        if maxtime != None:
            self.setMaxTime(maxtime)
Beispiel #11
0
    def __init__(self, maxtime=None, onmiss=None):
        EventBus.__init__(self)

        self.sched = s_sched.getGlobSched()
        self.onmiss = onmiss

        self.cache = {}
        self.lasthit = {}
        self.schevt = None
        self.maxtime = None
        self.cachelock = threading.Lock()

        self.onfini( self._onCacheFini )

        if maxtime != None:
            self.setMaxTime(maxtime)
Beispiel #12
0
    def __init__(self, maxtime=None):
        EventBus.__init__(self)

        self.sched = s_sched.getGlobSched()
        self.onmiss = None

        self.cache = {}
        self.lasthit = {}
        self.cachelock = threading.Lock()

        self.onfini( self._onCacheFini )

        self.schevt = None
        self.maxtime = maxtime

        if self.maxtime != None:
            self._checkCacheTimes()