@serverboards.rpc_method def touchfile(filename="/tmp/auth-py-touched", **_kwargs): import datetime serverboards.print("Touch file ", filename) with open(filename, "w") as fd: fd.write(str(datetime.datetime.now())) return True @serverboards.rpc_method def test_rate_limiting(count): # print("Sending %s events" % count, file=sys.stderr) for i in range(count): # print("Sending event %d" % i, file=sys.stderr) serverboards.rpc.event("count_for_rate_limiting", i) return "ok" @serverboards.rpc_method def server_updated(service): serverboards.info("From plugin: Updating '%s' service" % service["name"], service=service) serverboards.rpc.event("event.emit", "test.service.updated", {"ok": True}) serverboards.rpc.subscribe("service.updated[serverboards.test.auth/server]", server_updated) # print(serverboards.__dir(), file=sys.stderr) serverboards.loop() # debug=sys.stderr)
#!/usr/bin/python3 import serverboards, time @serverboards.rpc_method def simple_trigger(id): serverboards.rpc.reply(id) while True: serverboards.rpc.event("trigger", state="tick", id=id) time.sleep(0.2) serverboards.loop() # debug=sys.stderr)
#!/usr/bin/python3 import serverboards from serverboards import rpc_method, rpc @rpc_method def test1(): print("Test1, call test2") ret = rpc.call("test2") print("Test1 result", ret) return ret @rpc_method def test3(): print("Test3, ok") return "kool" serverboards.rpc.set_debug() serverboards.loop()
@serverboards.rpc_method def tag_change(id, service, tag): class TagUpdated: def __init__(self, service): self.tags=service["tags"] self.is_in=False self.service_id=service["uuid"] def check(self, service): #serverboards.debug("Check if service changed status %s %s %s %s"%(self.is_in, tag, service["tags"], tag in service["tags"])) if service["uuid"]!=self.service_id: #serverboards.debug("Not for me") return if self.is_in: if not tag in service["tags"]: serverboards.rpc.event("trigger", {"id" : id, "state" : "removed"}) self.is_in=False else: if tag in service["tags"]: serverboards.rpc.event("trigger", {"id" : id, "state" : "added"}) self.is_in=True subscription_id = serverboards.rpc.subscribe("service.updated[%s]"%service["uuid"], TagUpdated(service).check) return subscription_id @serverboards.rpc_method def tag_change_clear(id): serverboards.rpc.unsubscribe(id) serverboards.loop(debug=False)