Improve run-service plumbing

This commit is contained in:
Jeremy Dormitzer 2019-11-18 08:27:11 -05:00
parent a04ddf298d
commit d076216fc3

View File

@ -3125,13 +3125,13 @@ Some functions to make my day job easier.
;; TODO add some better process handling, e.g. gracefully kill services on restart
(defun run-service (name program &rest args)
(defun run-service (name program args &optional buffer-size)
(let ((bufname (format "*%s*" name)))
(apply #'make-comint-in-buffer name bufname program nil args)
(with-current-buffer bufname
(set (make-local-variable 'comint-output-filter-functions)
(cons #'comint-truncate-buffer comint-output-filter-functions))
(set (make-local-variable 'comint-buffer-maximum-size) 400)
(set (make-local-variable 'comint-buffer-maximum-size) (or buffer-size 100))
(toggle-truncate-lines 1))))
(defmacro with-venv (venv &rest body)
@ -3153,12 +3153,12 @@ Some functions to make my day job easier.
(if (not no-gunicorn)
(run-service "lola-server"
"gunicorn"
"-c"
"server/web/gunicorn.conf.py"
"-b"
"127.0.0.1:7200"
"bin.start_web:init_and_create_flask_app()")
(run-service "lola-server" "python" "bin/start_web.py"))))))
'("-c"
"server/web/gunicorn.conf.py"
"-b"
"127.0.0.1:7200"
"bin.start_web:init_and_create_flask_app()"))
(run-service "lola-server" "python" '("bin/start_web.py")))))))
(defun lola-server-celery-worker ()
(interactive)
@ -3167,16 +3167,16 @@ Some functions to make my day job easier.
(with-env-from-file "~/lola/lola-server/.env"
(run-service "lola-server-celery-worker"
"python"
"bin/start_celery_worker.py"
"-P"
"gevent")))))
'("bin/start_celery_worker.py"
"-P"
"gevent"))))))
(defun lola-travel-service ()
(interactive)
(with-venv "travel-service"
(with-default-directory "~/lola/lola-travel-service"
(with-env-from-file "~/lola/lola-travel-service/.env"
(run-service "lola-travel-service" "python" "bin/start_web.py")))))
(run-service "lola-travel-service" "python" '("bin/start_web.py"))))))
(defun lola-travel-service-celery ()
(interactive)
@ -3185,16 +3185,17 @@ Some functions to make my day job easier.
(with-env-from-file "~/lola/lola-travel-service/.env"
(run-service "lola-travel-service-celery"
"python"
"bin/start_celery_workers.py"
"-Q"
"default,io_pool,cpu_pool,priority_io_pool,priority_cpu_pool")))))
'("bin/start_celery_workers.py"
"-Q"
"default,io_pool,cpu_pool,priority_io_pool,priority_cpu_pool")
50)))))
(defun lola-secrets ()
(interactive)
(with-venv "secrets"
(with-default-directory "~/lola/secrets"
(with-env-from-file "~/lola/secrets/.env"
(run-service "lola-secrets" "python" "bin/cmdline.py" "www")))))
(run-service "lola-secrets" "python" '("bin/cmdline.py" "www"))))))
(defun lola-desktop (env)
(interactive
@ -3203,7 +3204,7 @@ Some functions to make my day job easier.
'("local" "development" "staging"))))
(with-env `(("LOLA_ENV" . ,env))
(with-default-directory "~/lola/lola-desktop"
(run-service "lola-desktop" "npm" "start"))))
(run-service "lola-desktop" "npm" '("start")))))
(defun lola-wallet (env)
(interactive
@ -3212,7 +3213,7 @@ Some functions to make my day job easier.
'("local" "development" "staging"))))
(with-env `(("LOLA_ENV" . ,env))
(with-default-directory "~/lola/wallet"
(run-service "lola-wallet" "npm" "start"))))
(run-service "lola-wallet" "npm" '("start")))))
(defun lola-run-all ()
(interactive)
@ -3227,21 +3228,21 @@ Some functions to make my day job easier.
(defun run-luigid ()
(interactive)
(run-python-service
"luigid"
"~/lola/data-pipeline"
"data-pipeline"
"luigid"
'()
"~/lola/data-pipeline/.env"))
(with-venv "data-pipeline"
(with-default-directory "~/lola/data-pipeline"
(with-env-from-file "~/lola/data-pipeline/.env"
(run-service
"luigid"
"luigid"
'())))))
(defun run-prometheus ()
(interactive)
(run-service
"prometheus"
"~/prometheus"
"prometheus"
'("--config.file=prometheus.yml")))
(with-default-directory "~/prometheus"
(run-service
"prometheus"
"prometheus"
'("--config.file=prometheus.yml"))))
(defun release-manager ()
(interactive)