pods: ops value in describe
This commit is contained in:
parent
859529b44b
commit
67639183eb
7 changed files with 25 additions and 17 deletions
12
doc/pods.md
12
doc/pods.md
|
|
@ -121,7 +121,8 @@ The pod should reply to this request with a message in the vein of:
|
|||
{"format" "json"
|
||||
"namespaces"
|
||||
[{"name" "pod.lispyclouds.sqlite"
|
||||
"vars" [{"name" "execute!"}]}]}
|
||||
"vars" [{"name" "execute!"}]}]
|
||||
"ops" {"shutdown" {}}}
|
||||
```
|
||||
|
||||
In this reply, the pod declares that payloads will be encoded and decoded using
|
||||
|
|
@ -133,6 +134,12 @@ this message from the pod's stdout.
|
|||
|
||||
Upon receiving this message, babashka creates these namespaces and vars.
|
||||
|
||||
The optional `ops` value communicates which ops the pod supports, beyond
|
||||
`describe` and `invoke`. It is a map of op names and option maps. In the above
|
||||
example the pod declares that it supports the `shutdown` op. Since the
|
||||
`shutdown` op does not need any additional options right now, the value is an
|
||||
empty map.
|
||||
|
||||
As a babashka user, you can load the pod with:
|
||||
|
||||
``` clojure
|
||||
|
|
@ -180,7 +187,8 @@ Now you know most there is to know about the pod protocol!
|
|||
|
||||
#### shutdown
|
||||
|
||||
When babashka is about to exit, it sends a `{"op" "shutdown"}` message and waits
|
||||
When babashka is about to exit, it sends an `{"op" "shutdown"}` message, if the
|
||||
pod has declared that it supports it in the `describe` response. Then it waits
|
||||
for the pod process to end. This gives the pod a chance to clean up resources
|
||||
before it exits.
|
||||
|
||||
|
|
|
|||
|
|
@ -105,10 +105,6 @@ fn handle_incoming(val: bc::Value) {
|
|||
_ => panic!(var)
|
||||
};
|
||||
},
|
||||
"shutdown" => {
|
||||
// TODO: clean up stuff?
|
||||
std::process::exit(0);
|
||||
}
|
||||
_ => panic!(op)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@
|
|||
(case op
|
||||
:describe (do (write {"format" "edn"
|
||||
"namespaces" [{"name" "pod.babashka.hsqldb"
|
||||
"vars" [{"name" "execute!"}]}]})
|
||||
"vars" [{"name" "execute!"}]}]
|
||||
"ops" {"shutdown" {}}})
|
||||
(recur))
|
||||
:invoke (let [var (-> (get message "var")
|
||||
read-string
|
||||
|
|
|
|||
|
|
@ -56,8 +56,6 @@ def main():
|
|||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
elif op == "shutdown":
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
2
sci
2
sci
|
|
@ -1 +1 @@
|
|||
Subproject commit 806cf61eeff31869727e205a8f1a7021a0ea5b49
|
||||
Subproject commit c55a1ef672c82a06f540e91c138d5689b679e02d
|
||||
|
|
@ -108,21 +108,25 @@
|
|||
stdin (.getOutputStream p)
|
||||
stdout (.getInputStream p)
|
||||
stdout (java.io.PushbackInputStream. stdout)
|
||||
_ (add-shutdown-hook!
|
||||
(fn []
|
||||
(write stdin {"op" "shutdown"
|
||||
"id" (next-id)})
|
||||
(.waitFor p)))
|
||||
_ (write stdin {"op" "describe"
|
||||
"id" (next-id)})
|
||||
reply (read stdout)
|
||||
format (-> (get reply "format") bytes->string keyword)
|
||||
ops (some->> (get reply "ops") keys (map keyword) set)
|
||||
pod {:process p
|
||||
:pod-spec pod-spec
|
||||
:stdin stdin
|
||||
:stdout stdout
|
||||
:chans (atom {})
|
||||
:format format}
|
||||
:format format
|
||||
:ops ops}
|
||||
_ (add-shutdown-hook!
|
||||
(fn []
|
||||
(if (contains? ops :shutdown)
|
||||
(do (write stdin {"op" "shutdown"
|
||||
"id" (next-id)})
|
||||
(.waitFor p))
|
||||
(.destroy p))))
|
||||
pod-namespaces (get reply "namespaces")
|
||||
vars-fn (fn [ns-name-str vars]
|
||||
(reduce
|
||||
|
|
|
|||
|
|
@ -60,7 +60,8 @@
|
|||
{"name" "assoc"}
|
||||
{"name" "error"}
|
||||
{"name" "print"}
|
||||
{"name" "print-err"}]}]})
|
||||
{"name" "print-err"}]}]
|
||||
"ops" {"shutdown" {}}})
|
||||
(recur))
|
||||
:invoke (let [var (-> (get message "var")
|
||||
read-string
|
||||
|
|
|
|||
Loading…
Reference in a new issue