def test_service_start(): process = pyservice.load_process( 'tests.processes.simple_process.SimpleProcess') service = pyservice.Service(process) service.start() assert process <> None, process assert service <> None, service
def main(): USE_SERVICE = False if USE_SERVICE: pyservice.Service('python-db', daemon_main=execute_query, client_receiver=lambda x: display_output(x)).run() else: out = execute_query(sys.argv) display_output(out)
def service(api): ''' Return a service with a simple api ''' return pyservice.Service(**api)
def test_run_process1(self): process2 = pyservice.load_process( 'tests.processes.few_simple_process.SimpleProcess2') service2 = pyservice.Service(process2) service2.start()
from examples import load_api, basic_wsgi import pyservice service = pyservice.Service(**load_api('echo/api.json')) @service.operation("greet") def greet(request, response, context): name = request.name city = request.city if not name: raise service.exceptions.InvalidName("Surely you have a name!") if not city: raise service.exceptions.InvalidCity( "Please tell me where you're from.") response.greeting = "Hello, {}!".format(name) response.question = "How's the weather in {}?".format(city) @service.operation("echo") def echo(request, response, context): response.value = request.value # Let's add a plugin for auth. This is an "operation" scope because we need # access to the operation parameters. The "request" scope is for pre/post # plugins, that need to ensure the request has been serialized before they # close (such as sqlalchemy) # For now we'll only authenticate calls to the echo operation, # with some super secret credentials