Add convencience functions to start servers

This commit is contained in:
Jeremy Dormitzer 2019-02-26 17:44:45 -05:00
parent cd7e9fb3c3
commit 6a01e6d17f

View File

@ -2530,3 +2530,107 @@ GraphQL environments:
(local . ("http://localhost:7200/api/graphql" .
,(password-store-get "lola-graphql-local-token")))))
#+END_SRC
* Lola
Some functions to make my day job easier. I need to clean these up and put a nice abstraction over them. It goes something like:
1. Define the buffer name and the working directory
2. Kill and re-create the buffer if it exists, then switch to it
3. Run some setup functions
4. Enter eshell mode and run a command
5. profit
#+BEGIN_SRC emacs-lisp
(defun lola-server ()
(interactive)
(if-let ((buf (get-buffer "*lola-server*")))
(kill-buffer buf))
(let ((buf (get-buffer-create "*lola-server*")))
(switch-to-buffer buf)
(cd "~/lola/lola-server")
(eshell-mode)
(eshell/deactivate)
(direnv-update-directory-environment (eshell/pwd))
(pyvenv-workon "lola-server")
(insert "gunicorn -t 120 -c server/web/gunicorn.conf.py bin.start_web:init_and_create_flask_app\\(\\)")
(eshell-send-input)))
(defun lola-celery-worker ()
(interactive)
(if-let ((buf (get-buffer "*lola-celery-worker*")))
(kill-buffer buf))
(let ((buf (get-buffer-create "*lola-celery-worker*")))
(switch-to-buffer buf)
(cd "~/lola/lola-server")
(eshell-mode)
(eshell/deactivate)
(direnv-update-directory-environment (eshell/pwd))
(pyvenv-workon "lola-server")
(insert "python bin/start_celery_worker.py -P gevent")
(eshell-send-input)))
(defun lola-travel-service ()
(interactive)
(if-let ((buf (get-buffer "*lola-travel-service*")))
(kill-buffer buf))
(let ((buf (get-buffer-create "*lola-travel-service*")))
(switch-to-buffer buf)
(cd "~/lola/lola-travel-service")
(eshell-mode)
(eshell/deactivate)
(direnv-update-directory-environment (eshell/pwd))
(pyvenv-workon "travel-service")
(insert "python bin/start_web.py")
(eshell-send-input)))
(defun lola-secrets ()
(interactive)
(if-let ((buf (get-buffer "*lola-secrets*")))
(kill-buffer buf))
(let ((buf (get-buffer-create "*lola-secrets*")))
(switch-to-buffer buf)
(cd "~/lola/secrets")
(eshell-mode)
(eshell/deactivate)
(direnv-update-directory-environment (eshell/pwd))
(pyvenv-workon "secrets")
(insert "python bin/cmdline.py www")
(eshell-send-input)))
(defun lola-desktop (env)
(interactive
(list (ido-completing-read+
"Environment: "
'("local" "development" "staging"))))
(if-let ((buf (get-buffer "*lola-desktop*")))
(kill-buffer buf))
(let ((buf (get-buffer-create "*lola-desktop*")))
(switch-to-buffer buf)
(cd "~/lola/lola-desktop")
(eshell-mode)
(setenv "LOLA_ENV" env)
(insert "npm start")
(eshell-send-input)))
(defun lola-wallet ()
(interactive
(list (ido-completing-read+
"Environment: "
'("local" "development" "staging"))))
(if-let ((buf (get-buffer "*lola-wallet*")))
(kill-buffer buf))
(let ((buf (get-buffer-create "*lola-wallet*")))
(switch-to-buffer buf)
(cd "~/lola/wallet")
(eshell-mode)
(setenv "LOLA_ENV" "local")
(insert "npm start")
(eshell-send-input)))
(jdormit/define-prefix "L" "lola")
(leader-def-key "Ls" #'lola-server)
(leader-def-key "Lc" #'lola-celery-worker)
(leader-def-key "Lt" #'lola-travel-service)
(leader-def-key "Ld" #'lola-desktop)
(leader-def-key "Lw" #'lola-wallet)
(leader-def-key "LS" #'lola-secrets)
#+END_SRC