From ff645a6677f040f8ffaa480c9518cb62ae03ed48 Mon Sep 17 00:00:00 2001 From: Adam Cooke Date: Wed, 26 Apr 2017 20:48:04 +0100 Subject: [PATCH] add script to set process concurrency on start/restart/run from config --- .gitignore | 2 ++ bin/postal | 3 +++ config/postal.example.yml | 3 +++ script/update_process_concurrency.rb | 16 ++++++++++++++++ 4 files changed, 24 insertions(+) create mode 100755 script/update_process_concurrency.rb diff --git a/.gitignore b/.gitignore index 444ec30..c80c54e 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ config/signing.key public/assets vendor/bundle + +Procfile.local diff --git a/bin/postal b/bin/postal index 0006fa7..8560bf7 100755 --- a/bin/postal +++ b/bin/postal @@ -30,6 +30,7 @@ cd $ROOT_DIR # Run the right command case "$1" in start) + run "bundle exec ruby script/update_process_concurrency.rb" run "procodile start" ;; @@ -38,6 +39,7 @@ case "$1" in ;; restart) + run "bundle exec ruby script/update_process_concurrency.rb" run "procodile restart" ;; @@ -46,6 +48,7 @@ case "$1" in ;; run) + run "bundle exec ruby script/update_process_concurrency.rb" run "LOG_TO_STDOUT=1 procodile start -f --no-respawn --stop-when-none" ;; diff --git a/config/postal.example.yml b/config/postal.example.yml index b984f67..8c9ba55 100644 --- a/config/postal.example.yml +++ b/config/postal.example.yml @@ -17,6 +17,9 @@ general: use_ip_pools: false exception_url: null +workers: + quantity: 1 + logging: stdout: false max_log_file_size: 20 diff --git a/script/update_process_concurrency.rb b/script/update_process_concurrency.rb new file mode 100755 index 0000000..a5de27d --- /dev/null +++ b/script/update_process_concurrency.rb @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby + +require File.expand_path('../../lib/postal/config', __FILE__) +worker_quantity = Postal.config.workers&.quantity || 1 +hash = { + 'processes' => { + 'worker' => { + 'quantity' => worker_quantity + }, + 'fast' => { + 'quantity' => Postal.config.fast_server ? 1 : 0 + } + } +}.to_yaml + +File.open(Postal.app_root.join('Procfile.local'), 'w') { |f| f.write(hash + "\n")}