Disable signal handlers on AWS lambdas via env var (#462)

* Disable handle-sigint! when BABASHKA_DISABLE_PIPE_SIGNAL_HANDLER is true

This allows babashka to be run in an AWS lambda.

* Rename BABASHKA_DISABLE_PIPE_SIGNAL_HANDLER to BABASHKA_DISABLE_SIGNAL_HANDLERS

Any signal handler used in AWS lambdas will not work. This simplifies/shortens
the naming of the env var.
This commit is contained in:
Chowlz 2020-06-08 12:27:40 -07:00 committed by GitHub
parent f15d609b45
commit 480d613b62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 9 deletions

View file

@ -803,8 +803,8 @@ repo](https://github.com/babashka/babashka.pods).
## Package babashka script as a AWS Lambda ## Package babashka script as a AWS Lambda
AWS Lambda runtime doesn't support signals, therefore babashka has to disable AWS Lambda runtime doesn't support signals, therefore babashka has to disable
handling of the SIGPIPE. This can be done by setting handling of SIGINT and SIGPIPE. This can be done by setting
`BABASHKA_DISABLE_PIPE_SIGNAL_HANDLER` to `true`. `BABASHKA_DISABLE_SIGNAL_HANDLERS` to `true`.
## Articles, podcasts and videos ## Articles, podcasts and videos

View file

@ -9,7 +9,7 @@
(identical? :PIPE @pipe-state)) (identical? :PIPE @pipe-state))
(defn handle-pipe! [] (defn handle-pipe! []
(when-not (= "true" (System/getenv "BABASHKA_DISABLE_PIPE_SIGNAL_HANDLER")) (when-not (= "true" (System/getenv "BABASHKA_DISABLE_SIGNAL_HANDLERS"))
(Signal/handle (Signal/handle
(Signal. "PIPE") (Signal. "PIPE")
(reify SignalHandler (reify SignalHandler

View file

@ -6,9 +6,10 @@
(set! *warn-on-reflection* true) (set! *warn-on-reflection* true)
(defn handle-sigint! [] (defn handle-sigint! []
(Signal/handle (when-not (= "true" (System/getenv "BABASHKA_DISABLE_SIGNAL_HANDLERS"))
(Signal. "INT") (Signal/handle
(reify SignalHandler (Signal. "INT")
(handle [_ _] (reify SignalHandler
;; This is needed to run shutdown hooks on interrupt, System/exit triggers those (handle [_ _]
(System/exit 0))))) ;; This is needed to run shutdown hooks on interrupt, System/exit triggers those
(System/exit 0))))))