Exemple #1
0
from ernie import mod, start
from ernie import Ernie
from time import sleep


def calc_add(a, b):
    return a + b


def slowcalc_add(a, b):
    sleep(2)
    return a + b


def slowcalc_superslow():
    sleep(10)


def errorcalc_add(a, b):
    raise Exception("oops!")


mod('calc').fun('add', calc_add)
mod('slowcalc').fun('add', slowcalc_add)
mod('slowcalc').fun('superslow', slowcalc_superslow)
mod('errorcalc').fun('add', errorcalc_add)

if __name__ == "__main__":
    start()
Exemple #2
0
#!/usr/bin/env python

from ernie import mod, start
from ernie import Ernie
from time import sleep


def calc_add(a, b):
    return a + b

def slowcalc_add(a,b):
    sleep(2)
    return a + b

def slowcalc_superslow():
    sleep(10)

def errorcalc_add(a,b):
    raise Exception("oops!")

mod('calc').fun('add', calc_add)
mod('slowcalc').fun('add', slowcalc_add)
mod('slowcalc').fun('superslow', slowcalc_superslow)
mod('errorcalc').fun('add', errorcalc_add)

if __name__ == "__main__":
    start()
Exemple #3
0
 def testModFun(self):
     ernie.mod('test').funs.clear()
     ernie.mod('test').fun('sstr', sstr)
     self.failUnlessEqual(ernie.mod('test').funs.keys(), ['sstr'])
     self.failUnlessEqual(ernie.mod('test').funs['sstr'], sstr)
Exemple #4
0
pile = eventlet.GreenPile()
def fetch(path, fromTime, untilTime=None):
    fromTime = timegm(fromTime.timetuple())

    if untilTime != None:
        untilTime =  timegm(untilTime.timetuple())

    arrayOfValues = []
    arrayOfTimeInfos = []
    files = glob.glob(path + ".wsp")
    for i in range(len(files)):
        pile.spawn(single_fetch, files[i], fromTime, untilTime)

    for (timeInfo, values) in pile:
        arrayOfValues.append(values)
        arrayOfTimeInfos.append(timeInfo)

    if arrayOfTimeInfos.count(arrayOfTimeInfos[0]) == len(arrayOfTimeInfos):
        values = [sum(v) for v in zip(*arrayOfValues)]
        (start, end, step) = arrayOfTimeInfos[0]
        return (start, end, step, values)
    else:
        return False

mod('whisbert').fun('create', create)
mod('whisbert').fun('update', update)
mod('whisbert').fun('fetch', fetch)

if __name__ == "__main__":
    start()
Exemple #5
0
 def testMod(self):
     ernie.Ernie.mods.clear()
     ernie.mod('test')
     self.failUnlessEqual(ernie.Ernie.mods.keys(), ['test'])
     self.failUnlessEqual(ernie.mod('test').name, 'test')

def iter_fib(n):
    a, b = 0, 1
    for i in range(n):
        a, b = b, a + b
    # Normally this will "return a" but apparently there's an erlastic bug
    # that fails deserialization on bigints. Just return 1 and call it a day,
    # this is for testing only.
    return 1


def io_task(n=0):
    try:
        fd = TemporaryFile()
        while n != 0:
            fd.write("JUNKJUNKJUNKJUNKJUNKJUNK")
            n -= 1
        fd.close()
    except IOError:
        pass
    except OSError:
        pass
    return 1

mod('fibmodule').fun('iter_fib', iter_fib)
mod('fibmodule').fun('io_task', io_task)

if __name__ == "__main__":
    start(daemon=False, async=True, forking=True)
Exemple #7
0
 def testModFun(self):
     ernie.mod('test').funs.clear()
     ernie.mod('test').fun('sstr', sstr)
     self.failUnlessEqual(ernie.mod('test').funs.keys(), ['sstr'])
     self.failUnlessEqual(ernie.mod('test').funs['sstr'], sstr)
Exemple #8
0
 def testMod(self):
     ernie.Ernie.mods.clear()
     ernie.mod('test')
     self.failUnlessEqual(ernie.Ernie.mods.keys(), ['test'])
     self.failUnlessEqual(ernie.mod('test').name, 'test')

def calc_add(a, b):
    return a + b


def slowcalc_add(a, b):
    sleep(2)
    return a + b


def slowcalc_superslow():
    sleep(10)


def errorcalc_add(a, b):
    raise Exception("oops!")


mod("calc").fun("add", calc_add)
mod("slowcalc").fun("add", slowcalc_add)
mod("slowcalc").fun("superslow", slowcalc_superslow)
mod("errorcalc").fun("add", errorcalc_add)

if __name__ == "__main__":
    """ Starts the server.
        WARNING: you will have to kill process to stop it as it
                 will ignore Ctrl+C keyboard interrupts.
    """
    start()