The Client
$ export CATBUS_URL='http://127.1:8888/test'
$ alias catbus='pipenv run python3 -m catbus.client'
$ catbus
DEBUG Fetching http://127.1:8888/test
url: http://127.1:8888/test/
links: MyEndpoint, Total
actions: echo, test, Job
embeds: 'MyEndpoint':<__main__.RemoteObject object at 0x108db74a8>,
'Total':<__main__.RemoteObject object at 0x108db7be0>
attributes:
$ catbus echo --x='Test!'
DEBUG Fetching http://127.1:8888/test
DEBUG Fetching http://127.1:8888/test/echo
Test!
$ catbus MyEndpoint
DEBUG Fetching http://127.1:8888/test
DEBUG MyEndpoint <cached>
url: http://127.1:8888/test/MyEndpoint
links: Two
actions: which_demo, demo, rpc_one, rpc_two, rpc_three, now
embeds: 'Two':<__main__.RemoteObject object at 0x108673978>
attributes:
$ catbus MyEndpoint:rpc_one --a=1 --b=2
DEBUG Fetching http://127.1:8888/test
DEBUG MyEndpoint <cached>
DEBUG Fetching http://127.1:8888/test/MyEndpoint/rpc_one
3
$ catbus MyEndpoint:now
DEBUG Fetching http://127.1:8888/test
DEBUG MyEndpoint <cached>
DEBUG Fetching http://127.1:8888/test/MyEndpoint/now
2018-02-08 16:43:13.923806+00:00
$
$ catbus MyEndpoint:Two
DEBUG Fetching http://127.1:8888/test
DEBUG MyEndpoint <cached>
url: http://127.1:8888/test/MyEndpoint/Two
links:
actions: test, expensive
embeds:
attributes:
$ catbus MyEndpoint:Two:expensive --value="This gets polled for"
DEBUG Fetching http://127.1:8888/test
DEBUG MyEndpoint <cached>
DEBUG Two <cached>
DEBUG Fetching http://127.1:8888/test/MyEndpoint/Two/expensive
DEBUG Fetching http://127.1:8888/test/MyEndpoint/Two/expensive/wait?value=%22This+gets+polled+for%22&count=3
DEBUG Fetching http://127.1:8888/test/MyEndpoint/Two/expensive/wait?value=%22This+gets+polled+for%22&count=2
DEBUG Fetching http://127.1:8888/test/MyEndpoint/Two/expensive/wait?value=%22This+gets+polled+for%22&count=1
DEBUG Fetching http://127.1:8888/test/MyEndpoint/Two/expensive/wait?value=%22This+gets+polled+for%22&count=0
This gets polled for
And the server code:
from catbus import client, server
import sys
from datetime import datetime, timezone
def make_server():
n = server.Registry(name="test")
@n.add()
def echo(x):
return x
@n.add()
class MyEndpoint(server.Service):
class Two(server.Service):
@server.waiter()
def expensive(value):
return server.Waiter(value=value,count=3)
@expensive.ready()
def expensive(value, count):
if count > 0:
return server.Waiter(value=value, count=count-1)
else:
return value
def rpc_one(a,b):
return a+b
def now():
return datetime.now(timezone.utc)
return server.Server(n.app(), port=8888)
def run():
server_thread = make_server()
server_thread.start()
print("Running on ",server_thread.url)
try:
while True: pass
finally:
server_thread.stop()
if __name__ == '__main__':
run()
(See example.py
in the repo)
the WIP is at http://github.com/imbal/catbus