def run(self): try: from scheduler import setup_scheduler, scheduler except ImportError: from example1.scheduler import setup_scheduler, scheduler while not self.got_sigterm(): logging.info("Starting") self.program = oi.Program('example1', config.ctl_url) self.program.logger = self.logger self.program.add_command('ping', lambda: 'pong') self.program.add_command('state', lambda: self.program.state) def restart(): logging.warning('Restarting') self.program.continue_event.set() self.program.restart = restart setup_scheduler(self.program) if hasattr(config, 'register_hook'): config.register_hook(ctx=dict( locals=locals(), globals=globals(), program=self.program)) self.program.run() logging.warning("Stopping") scheduler.shutdown() if not self.program.continue_event.wait(0.1): break self.stop() os.unlink('/tmp/demo.pid') os.execl(sys.executable, sys.argv[0], 'start') if self.got_sigterm(): self.program.stop_function()
def main(): program = oi.Program('example1', config.ctl_url) program.add_command('ping', lambda: 'pong') program.add_command('state', lambda: program.state) try: from scheduler import setup_scheduler, scheduler except ImportError: from example1.scheduler import setup_scheduler, scheduler setup_scheduler(program) if hasattr(config, 'register_hook'): config.register_hook( ctx=dict(locals=locals(), globals=globals(), program=program)) program.run() scheduler.shutdown()
def main(): program = oi.Program('my program', 'ipc:///tmp/programd.sock') program.add_command('ping', lambda: 'pong') program.add_command('state', lambda: program.state, 'show program state') program.add_command( 'store', lambda key, val: setattr(program.state, key, val) and True, 'store an item') program.add_command('get', lambda key: getattr(program.state, key, None), 'get an item') program.run()
def main(): addr = sys.argv.pop(1) program = oi.Program('my program', addr) program.add_command( 'ping', lambda: 'pong') program.add_command( 'state', lambda: program.state, 'show program state') program.add_command( 'store', lambda key, val: setattr(program.state, key, val) or True, 'store an item') program.add_command( 'get', lambda key: getattr(program.state, key, None), 'get an item') program.run()
def setUp(self): self.address = 'ipc:///tmp/test-programd.sock' self.p = oi.Program('programd', self.address) self.ctl = oi.CtlProgram('programctl', self.address)
def main(): program = oi.Program('my program', 'ipc:///tmp/oi-random_string.sock') program.add_command('ping', lambda p: 'pong') program.add_command('state', lambda p: p.state) program.run()