class TestCase(TestCase): withpool = 1 taskdir = "unuk.contrib.tasks.tests.tlib" def setUp(self): pool = getpool(self.withpool) self.controller = Controller(pool=pool, task_modules=["{0}.*".format(self.taskdir)], beat=0.5) self.controller.start() self.scheduler = self.controller.scheduler self.registry = registry def tearDown(self): self.controller.wait()
class JsonCalculator(JSONRPC): '''JSON RPC Server with a task controller''' def __init__(self, pool): logger = get_logger(name = 'taskqueue') super(JsonCalculator,self).__init__(logger = logger) self.controller = Controller(pool).start() def jsonrpc_calculate(self, request, **kwargs): '''Dispatch new task and returns task id''' request = self.controller.dispatch('taskqueue.tasks.calctask', **kwargs) request.bind('success',callback) return request.info.todict() def jsonrpc_shutdown(self, request, **kwargs): self.stop() def stop(self): self.logger.info('Stopping calculation pool') self.controller.stop()
def __init__(self, pool): logger = get_logger(name = 'taskqueue') super(JsonCalculator,self).__init__(logger = logger) self.controller = Controller(pool).start()
def setUp(self): pool = getpool(self.withpool) self.controller = Controller(pool=pool, task_modules=["{0}.*".format(self.taskdir)], beat=0.5) self.controller.start() self.scheduler = self.controller.scheduler self.registry = registry