Compare commits

..

No commits in common. "4500cf9cb5f5890c94371edef8dab60b3043ea8c" and "c9420cf1a6577190bc1535bfee4f1bfa6ab0f6af" have entirely different histories.

4 changed files with 416 additions and 69 deletions

View File

@ -22,6 +22,17 @@
even-window-sizes nil) even-window-sizes nil)
(setq-default indent-tabs-mode nil) (setq-default indent-tabs-mode nil)
;; default to utf-8 for all the things
(set-charset-priority 'unicode)
(setq locale-coding-system 'utf-8
coding-system-for-read 'utf-8
coding-system-for-write 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
(setq default-process-coding-system '(utf-8-unix . utf-8-unix))
;; Always display line numbers in text/programming modes ;; Always display line numbers in text/programming modes
(add-hook 'prog-mode-hook #'display-line-numbers-mode) (add-hook 'prog-mode-hook #'display-line-numbers-mode)
(add-hook 'text-mode-hook #'display-line-numbers-mode)) (add-hook 'text-mode-hook #'display-line-numbers-mode))

View File

@ -1,7 +1,6 @@
;; -*- lexical-binding: t; -*- ;; -*- lexical-binding: t; -*-
;; A nice interface for running long-running local programs ;; A nice interface for running long-running local programs
;; Most actual prodigy services defined in local.el
(use-package prodigy (use-package prodigy
:commands (prodigy) :commands (prodigy)
:general :general
@ -11,6 +10,362 @@
(prodigy-completion-system 'default) (prodigy-completion-system 'default)
:config :config
(evil-collection-prodigy-setup) (evil-collection-prodigy-setup)
(general-def 'normal prodigy-mode-map "`" #'prodigy-display-process-file-or-buffer)) ;; Add ability to associate a file with service logs instead of a buffer
(defun prodigy-service-file (service)
"Return SERVICE file.
If SERVICE file exists, use that. If not, find the first SERVICE
tag that has a file and return that."
(let ((file (prodigy-service-or-first-tag-with service :file)))
(if (functionp file)
(prodigy-callback-with-plist file service)
file)))
(defun prodigy-display-process-file-or-buffer ()
(interactive)
(when-let (service (prodigy-service-at-pos))
(if-let (file (prodigy-service-file service))
(progn
(find-file-literally file)
(prodigy-view-mode)
(auto-revert-tail-mode)
(general-define-key
:states 'normal
:keymaps 'local
"Q" #'kill-this-buffer))
(prodigy-switch-to-process-buffer service))))
(general-def 'normal prodigy-mode-map "`" #'prodigy-display-process-file-or-buffer)
;; Add ability to inhibit all output processing
(defun prodigy-start-service (service &optional callback)
"Start process associated with SERVICE unless already started.
When CALLBACK function is specified, that is called when the
process has been started.
When the process is started, a timer starts and checks every
second for `prodigy-start-tryouts' times if the process is live.
If the process is not live after `prodigy-start-tryouts' seconds,
the process is put in failed status."
(declare (indent 1))
(unless (prodigy-service-started-p service)
(let* ((default-directory
(-if-let (cwd (prodigy-service-cwd service))
(f-full cwd)
default-directory))
(name (plist-get service :name))
(sudo (plist-get service :sudo))
(command (prodigy-service-command service))
(args (prodigy-service-args service))
(exec-path (append (prodigy-service-path service) exec-path))
(env (--map (s-join "=" it) (prodigy-service-env service)))
(process-environment (append env process-environment))
(process nil)
(create-process
(lambda ()
(unless process
(setq process (apply (if sudo 'prodigy-start-sudo-process 'start-process)
(append (list name nil command) args)))))))
(-when-let (init (prodigy-service-init service))
(funcall init))
(-when-let (init-async (prodigy-service-init-async service))
(let (callbacked)
(funcall
init-async
(lambda ()
(setq callbacked t)
(funcall create-process)))
(with-timeout
(prodigy-init-async-timeout
(error "Did not callback async callback within %s seconds"
prodigy-init-async-timeout))
(while (not callbacked) (accept-process-output nil 0.005)))))
(funcall create-process)
(let ((tryout 0))
(prodigy-every 1
(lambda (next)
(setq tryout (1+ tryout))
(if (process-live-p process)
(when callback (funcall callback))
(if (= tryout prodigy-start-tryouts)
(prodigy-set-status service 'failed)
(funcall next))))))
(plist-put service :process process)
(when (not (plist-get service :inhibit-process-filter))
(set-process-filter
process
(lambda (_ output)
(run-hook-with-args 'prodigy-process-on-output-hook service output))))
(set-process-query-on-exit-flag process nil))))
(add-hook 'prodigy-view-mode-hook (lambda () (toggle-truncate-lines 1)))
;; Actual service definitions begin here
(defun call-with-venv (venv callback)
(let ((venv-dir (cond
((file-exists-p venv) venv)
((file-exists-p
(substitute-in-file-name
(format "$WORKON_HOME/%s" venv)))
(substitute-in-file-name
(format "$WORKON_HOME/%s" venv)))
(t (error "virtual environment %s does not exist" venv)))))
(call-with-env-from-file (format "%s/bin/activate" venv-dir) callback)))
(defun kill-log-buffers ()
(interactive)
(kill-matching-buffers "\\.log$" nil t)
(message "Killed log buffers"))
(cl-defun python-service-setup (venv &optional env-file &key env-dir)
(lambda (done)
(call-with-venv
venv
(if env-file
(lambda ()
(call-with-env-from-file env-file done :dir env-dir))
done))))
(defun call-with-lola-env (callback)
(let ((process-environment
(cons (format "LOLA_ENV=%s"
(completing-read
"Environment: "
'("local" "development" "staging")))
process-environment)))
(funcall callback)))
(prodigy-define-tag
:name 'lola)
(prodigy-define-service
:name "lola-server (gunicorn)"
:tags '(lola backend)
:command "bash"
:args (lambda ()
(list
"-c"
"gunicorn -c server/web/gunicorn.conf.py \
-b 127.0.0.1:7200 bin.start_web:init_and_create_flask_app\\(\\) \
>> ~/lola/logs/lola-server.log 2>&1"))
:file "~/lola/logs/lola-server.log"
:inhibit-process-filter t
:cwd "~/lola/core-services/lola_server"
:stop-signal 'int
:truncate-output t
:init-async (python-service-setup "~/lola/core-services/.venv"
"~/lola/core-services/lola_server/.env"))
(prodigy-define-service
:name "lola-server celery worker"
:tags '(lola backend)
:command "python"
:args '("bin/start_celery_worker.py" "-P" "gevent" "-n" "lola-server")
:cwd "~/lola/core-services/lola_server"
:stop-signal 'int
:truncate-output t
:init-async (python-service-setup "~/lola/core-services/.venv"
"~/lola/core-services/lola_server/.env"))
(prodigy-define-service
:name "travel-service"
:tags '(lola backend)
:command "bash"
:args (lambda ()
(list
"-c" "python bin/start_web.py >> ~/lola/logs/travel-svc.log 2>&1"))
:cwd "~/lola/core-services/travel_service"
:file "~/lola/logs/travel-svc.log"
:inhibit-process-filter t
:stop-signal 'int
:truncate-output t
:init-async (python-service-setup "~/lola/core-services/.venv"
"~/lola/core-services/travel_service/.env"))
(prodigy-define-service
:name "travel-service celery worker"
:tags '(lola backend)
:command "bash"
:args (lambda ()
(list
"-c"
(concat "python "
"bin/start_celery_workers.py "
"-n " "travel-service "
">> ~/lola/logs/travel-svc-celery.log 2>&1")))
:file "~/lola/logs/travel-svc-celery.log"
:inhibit-process-filter t
:cwd "~/lola/core-services/travel_service"
:stop-signal 'int
:truncate-output t
:init-async (python-service-setup "~/lola/core-services/.venv"
"~/lola/core-services/travel_service/.env"))
(prodigy-define-service
:name "secrets"
:tags '(lola backend)
:command "python"
:args '("bin/cmdline.py" "www")
:env '(("PORT" "7450"))
:cwd "~/lola/secrets"
:truncate-output t
:stop-signal 'int
:init-async (python-service-setup "~/.pyenv/versions/secrets"
"~/lola/secrets/.env"))
(prodigy-define-service
:name "lola-desktop"
:tags '(lola frontend)
:command "npm"
:args '("start")
:cwd "~/lola/lola-desktop"
:port 3001
:env '(("PORT" "3001"))
:stop-signal 'int
:init-async #'call-with-lola-env)
(prodigy-define-service
:name "wallet"
:tags '(lola frontend)
:command "npm"
:args '("start")
:cwd "~/lola/wallet"
:stop-signal 'int
:env '(("PORT" "3000"))
:init-async #'call-with-lola-env)
(prodigy-define-service
:name "agent-console"
:command "npm"
:args '("start")
:cwd "~/lola/agent-console"
:stop-signal 'int
:env '(("PORT" "3002"))
:init-async (lambda (done)
(call-with-lola-env
(lambda ()
(nvm-use "v10.15.1" done)))))
(prodigy-define-service
:name "luigid"
:command "luigid"
:cwd "~/lola/data-pipeline"
:port 8082
:stop-signal 'int
:init-async (python-service-setup "data-pipeline"
"~/lola/data-pipeline/.env"))
(prodigy-define-service
:name "prometheus"
:command "prometheus"
:args '("--config.file=prometheus.yml")
:port 9090
:stop-signal 'int
:cwd "~/prometheus")
(prodigy-define-service
:name "priceline-service"
:tags '(lola backend)
:command "~/lola/python-services/priceline/bin/start.sh"
:args '("web-dev")
:cwd "~/lola/python-services"
:stop-signal 'int
:init-async (python-service-setup "~/lola/python-services/.venv"
"~/lola/python-services/priceline/.env"
:env-dir "~/lola/python-services"))
(prodigy-define-service
:name "priceline-cars-service"
:tags '(lola backend)
:command "bash"
:args '("-c"
"priceline_cars/bin/start.sh web-dev >> ~/lola/logs/priceline-cars.log 2>&1")
:cwd "~/lola/python-services"
:inhibit-process-filter t
:file "~/lola/logs/priceline-cars.log"
:stop-signal 'int
:init-async (python-service-setup "~/lola/python-services/.venv"
"~/lola/python-services/priceline_cars/.env"
:env-dir "~/lola/python-services"))
(prodigy-define-service
:name "threev-service"
:tags '(lola backend)
:command "~/lola/python-services/threev/bin/start.sh"
:args '("web-dev")
:cwd "~/lola/python-services"
:stop-signal 'int
:init-async (python-service-setup "~/lola/python-services/.venv"
"~/lola/python-services/threev/.env"
:env-dir "~/lola/python-services"))
(prodigy-define-service
:name "amd-flight-service"
:tags '(lola backend)
:command "~/lola/python-services/amd_flight/bin/start.sh"
:args '("web-dev")
:cwd "~/lola/python-services"
:stop-signal 'int
:init-async (python-service-setup "~/lola/python-services/.venv"
"~/lola/python-services/amd_flight/.env"
:env-dir "~/lola/python-services"))
(prodigy-define-service
:name "ean-hotels-service"
:tags '(lola backend)
:command "bash"
:args '("-c"
"ean_hotels/bin/start.sh web-dev >> ~/lola/logs/ean-hotels.log 2>&1")
:cwd "~/lola/python-services"
:inhibit-process-filter t
:file "~/lola/logs/ean-hotels.log"
:stop-signal 'kill
:init-async (python-service-setup "~/lola/python-services/.venv"
"~/lola/python-services/ean_hotels/.env"
:env-dir "~/lola/python-services"))
(prodigy-define-service
:name "smp-hotels-service"
:command "bash"
:args '("-c"
"smp_hotels/bin/start.sh web >> ~/lola/logs/smp-hotels.log 2>&1")
:cwd "~/lola/python-services"
:inhibit-process-filter t
:file "~/lola/logs/smp-hotels.log"
:stop-signal 'kill
:init-async (python-service-setup "~/lola/python-services/.venv"
"~/lola/python-services/smp_hotels/.env"
:env-dir "~/lola/python-services"))
(prodigy-define-service
:name "email-template-service"
:tags '(lola backend)
:command "npm"
:args '("start")
:cwd "~/lola/email-template-service"
:env '(("PORT" "7300"))
:stop-signal 'int
:init-async (lambda (done)
(nvm-use "10.15.1" done)))
(prodigy-define-service
:name "mabl-link-agent"
:command "link-agent"
:args (lambda ()
(list "-a" (password-store-get "mabl-link-agent")
"-n" "jdormit-macbook")))
(prodigy-define-service
:name "xray-daemon"
:command "xray_mac"
:args '("-o" "-n" "us-east-1"))
(prodigy-define-service
:name "spend-service"
:tags '(lola backend)
:command "~/lola/python-services/spend/bin/start.sh"
:args '("web-dev")
:cwd "~/lola/python-services"
:stop-signal 'int
:init-async (python-service-setup "~/lola/python-services/.venv"
"~/lola/python-services/spend/.env"
:env-dir "~/lola/python-services")))
(provide 'init-prodigy) (provide 'init-prodigy)

View File

@ -217,71 +217,54 @@
(defun run-command-recipe-maven () (defun run-command-recipe-maven ()
(when-let* ((root-dir (or (projectile-project-root) default-directory)) (when-let* ((root-dir (or (projectile-project-root) default-directory))
(local-pom-dir (locate-dominating-file default-directory "pom.xml")) (project-dir (locate-dominating-file root-dir "pom.xml")))
(project-dir (locate-dominating-file root-dir "pom.xml")) (list
(commands (list
(list :command-name "validate" (list :command-name "validate"
:command-line "mvn validate" :command-line "mvn validate"
:working-dir local-pom-dir) :working-dir project-dir)
(list :command-name "compile" (list :command-name "compile"
:command-line "mvn compile" :command-line "mvn compile"
:working-dir local-pom-dir) :working-dir project-dir)
(list :command-name "clean compile" (list :command-name "clean compile"
:command-line "mvn clean compile" :command-line "mvn clean compile"
:working-dir local-pom-dir) :working-dir project-dir)
(list :command-name "test" (list :command-name "test"
:command-line "mvn test -DfailIfNoTests=false" :command-line "mvn test -DfailIfNoTests=false"
:working-dir local-pom-dir) :working-dir project-dir)
(list :command-name "package" (list :command-name "package"
:command-line "mvn package" :command-line "mvn package"
:working-dir local-pom-dir) :working-dir project-dir)
(list :command-name "verify" (list :command-name "verify"
:command-line "mvn verify" :command-line "mvn verify"
:working-dir local-pom-dir) :working-dir project-dir)
(list :command-name "install" (list :command-name "install"
:command-line "mvn install" :command-line "mvn install"
:working-dir local-pom-dir) :working-dir project-dir)
(list :command-name "deploy" (list :command-name "deploy"
:command-line "mvn deploy" :command-line "mvn deploy"
:working-dir local-pom-dir) :working-dir project-dir)
(list :command-name "clean" (list :command-name "clean"
:command-line "mvn clean" :command-line "mvn clean"
:working-dir local-pom-dir) :working-dir project-dir)
(list :command-name "exec:java" (list :command-name "exec:java"
:command-line "mvn exec:java" :command-line "mvn compile exec:java"
:working-dir local-pom-dir) :working-dir project-dir)
(list :command-name "clean compile exec:java"
:command-line "mvn clean compile exec:java"
:working-dir local-pom-dir)
(when-let ((test-class (and (buffer-file-name) (when-let ((test-class (and (buffer-file-name)
(let ((case-fold-search nil)) (let ((case-fold-search nil))
(string-match-p ".*\\(Test\\|IT\\).*\\.java$" (string-match-p ".*\\(Test\\|IT\\).*\\.java$" (buffer-file-name)))
(buffer-file-name)))
(fboundp 'dap-java-test-class) (fboundp 'dap-java-test-class)
(dap-java-test-class)))) (dap-java-test-class))))
(list :command-name "test this class" (list :command-name "test this class"
:command-line (format "mvn test -DfailIfNoTests=false -Dtest=%s" test-class) :command-line (format "mvn test -DfailIfNoTests=false -Dtest=%s" test-class)
:working-dir local-pom-dir)) :working-dir project-dir))
(when-let ((test-method (and (buffer-file-name) (when-let ((test-method (and (buffer-file-name)
(let ((case-fold-search nil)) (let ((case-fold-search nil))
(string-match-p ".*\\(Test\\|IT\\).*\\.java$" (string-match-p ".*\\(Test\\|IT\\).*\\.java$" (buffer-file-name)))
(buffer-file-name)))
(fboundp 'dap-java-test-method-at-point) (fboundp 'dap-java-test-method-at-point)
(dap-java-test-method-at-point t)))) (dap-java-test-method-at-point t))))
(list :command-name "test this method" (list :command-name "test this method"
:command-line (format "mvn test -DfailIfNoTests=false -Dtest=%s" test-method) :command-line (format "mvn test -DfailIfNoTests=false -Dtest=%s" test-method)
:working-dir local-pom-dir))))) :working-dir project-dir)))))
(if (s-equals? local-pom-dir project-dir)
commands
(-concat commands
(-map (lambda (cmd)
(when cmd
(-> (-copy cmd)
(plist-put :command-name
(format "%s (root POM)"
(plist-get cmd :command-name)))
(plist-put :working-dir project-dir))))
commands)))))
(defun get-cargo-commands (dir) (defun get-cargo-commands (dir)
(when (executable-find "cargo") (when (executable-find "cargo")

View File

@ -114,7 +114,5 @@
(require 'init-lola) (require 'init-lola)
(require 'handwriting) (require 'handwriting)
(load (expand-file-name (concat user-emacs-directory "local.el")) 'noerror 'nomessage)
(when (file-exists-p custom-file) (when (file-exists-p custom-file)
(load custom-file 'noerror 'nomessage)) (load custom-file 'noerror 'nomessage))