Skip to content

Commit 3ef8cf2

Browse files
streaing functions moved into threads
1 parent fbc58e6 commit 3ef8cf2

File tree

5 files changed

+56
-34
lines changed

5 files changed

+56
-34
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@
2626
.idea
2727
/catalog.updated.yaml
2828
claude_desktop_config.json
29+
/set-secrets.sh

dev/containers.clj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(ns containers
2+
(:require [docker]))
3+
4+
(->> (docker/containers {})
5+
(map #(select-keys % [:Names :Status :State :Id :Image])))
6+
7+
'(:Ports
8+
:Image
9+
:Labels
10+
:Id
11+
:Mounts
12+
:HostConfig
13+
:Command
14+
:ImageID
15+
:Names
16+
:State
17+
:Created
18+
:NetworkSettings
19+
:Status)
46.3 KB
Loading

src/docker.clj

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@
380380
(string/join " ; ")))
381381

382382
(defn get-secrets [{:keys [secrets]}]
383-
(logger/info (format "getting secrets %s" secrets))
384383
(->> secrets
385384
(map (fn [[k v]]
386385
[v (:value (secrets-get (name k)))]))
@@ -424,18 +423,22 @@
424423
finished-channel (async/promise-chan)]
425424
(start x)
426425

427-
(async/go
428-
(try
429-
(let [s (:body (attach-container-stream-stdout x))]
430-
(doseq [line (line-seq (java.io.BufferedReader. (java.io.InputStreamReader. s)))]
431-
(cb line)))
432-
(catch Throwable e
433-
(println e))))
426+
(.start ^Thread
427+
(Thread.
428+
(fn []
429+
(try
430+
(let [s (:body (attach-container-stream-stdout x))]
431+
(doseq [line (line-seq (java.io.BufferedReader. (java.io.InputStreamReader. s)))]
432+
(cb line)))
433+
(catch Throwable e
434+
(logger/error "run-streaming-function" e))))))
434435

435436
;; watch the container
436-
(async/go
437-
(wait x)
438-
(async/>! finished-channel {:done :exited}))
437+
(.start ^Thread
438+
(Thread.
439+
(fn []
440+
(wait x)
441+
(async/put! finished-channel {:done :exited}))))
439442

440443
{:container x
441444
;; stopped channel

src/jsonrpc/prompt_change_events.clj

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,28 @@
6060
:unknown)
6161
(recur (async/<! debounced)))
6262
;; watch filesystem
63-
(async/thread
64-
(let [{x :container}
65-
(docker/run-streaming-function-with-no-stdin
66-
{:image "vonwig/inotifywait:latest"
67-
:labels {"com.docker.desktop.service" "true"}
68-
:volumes ["docker-prompts:/prompts"]
69-
:command ["-e" "create" "-e" "modify" "-e" "delete" "-q" "-m" "/prompts"]}
70-
(fn [line]
71-
(let [[_dir _event f] (string/split line #"\s+")]
72-
(async/>!!
73-
change-events-channel
74-
(cond
75-
(= f "registry.yaml")
76-
{:opts opts :f f :type :registry}
77-
(string/ends-with? f ".md")
78-
{:opts opts :f f :type :markdown}
79-
:else
80-
{})))))]
81-
(shutdown/schedule-container-shutdown
82-
(fn []
83-
(logger/info "inotifywait shutting down")
84-
(docker/kill-container x)
85-
(docker/delete x)))))))
63+
(let [{x :container}
64+
(docker/run-streaming-function-with-no-stdin
65+
{:image "vonwig/inotifywait:latest"
66+
:labels {"com.docker.desktop.service" "true"}
67+
:volumes ["docker-prompts:/prompts"]
68+
:command ["-e" "create" "-e" "modify" "-e" "delete" "-q" "-m" "/prompts"]}
69+
(fn [line]
70+
(let [[_dir _event f] (string/split line #"\s+")]
71+
(async/put!
72+
change-events-channel
73+
(cond
74+
(= f "registry.yaml")
75+
{:opts opts :f f :type :registry}
76+
(string/ends-with? f ".md")
77+
{:opts opts :f f :type :markdown}
78+
:else
79+
{})))))]
80+
(shutdown/schedule-container-shutdown
81+
(fn []
82+
(logger/info "inotifywait shutting down")
83+
(docker/kill-container x)
84+
(docker/delete x))))))
8685

8786
(comment
8887
(repl/setup-stdout-logger)

0 commit comments

Comments
 (0)